Ticket T1053128
Visible to All Users

DataGrid Editing - OnValueChanged event override does not save value

created 3 years ago

Hi!

i have the following code:

Razor
@(Html.DevExtreme().DataGrid<Company>() .ID("datagrid-companies") .DataSource(ds => { return ds.Mvc().Controller("Companies") .LoadAction(Globals.EntityControllerLoadAction) .UpdateAction(Globals.EntityControllerUpdateAction) .InsertAction(Globals.EntityControllerInsertAction) .DeleteAction(Globals.EntityControllerDeleteAction) .Key("Id"); }) .OnInitNewRow( @<text> function onInitNewRow(options) { options.data.ManualRequestsForCollections = true; } </text> ) .Editing(editing => { editing.Mode(GridEditMode.Popup); editing.AllowAdding(true); editing.AllowUpdating(true); editing.AllowDeleting(true); editing.UseIcons(true); editing.Popup(p => { p.Title("Compañia") .ShowTitle(true); }); editing.Form(f => { f.ShowValidationSummary(true); f.Items(items => { items.AddGroup().ColCount(2).ColSpan(2).Items(groupItems => { groupItems.AddSimpleFor(m => m.ManualRequestsForCollections).ColSpan(2).Editor(e => e.CheckBox().OnValueChanged(@"function(args) { onManualRequestsForCollectionsValueChanged(args, setValue); }")); }); }); }); }) .Columns(columns => { columns.AddFor(m => m.ManualRequestsForCollections).CellTemplate(@<text> [% if(data.ManualRequestsForCollections == true) { %] <span class="badge badge-success"></span> [% } else { %] <span class="badge badge-danger">No</span> [% } %] </text>).Width(Globals.DataGridMediumColumnWidth); }) ) <script> function onManualRequestsForCollectionsValueChanged(args, setValueMethod) { setValueMethod(args.value); var myDialog = DevExpress.ui.dialog.custom({ showTitle: false, messageHtml: "¡Recuerde que este cambio solo afecta a los nuevos envases y que los usuarios de las PDA's deben volver a inicar sesión para que los cambios tengan efecto!", buttons: [ { text: "Aceptar", onClick: function (b) { return { buttonText: b.component.option("text") } } }] }); myDialog.show(); } </script>

It seems that if I override the OnValueChanged function of the Checkbox, and the user only edit the value of the checkbox, the update function of the controller never executes. It is as if there are no changes for the specific row that has been modified.

If the code is empty, the onManualRequestsForCollectionsValueChanged function still does not work, so the custom dialog has nothing to do with it, it is simply due to the fact of overriding the event

Currently, from what I have read in your forums I have to use the setValue function.
The problem is that I can't do it. I have the error of SetValue is undefined. Can you help me and tell me what is missing from my code?

Best Regards.

Answers approved by DevExpress Support

created 3 years ago

Hello,

Handling the OnValueChanged event of an editor overrides the built-in dataGrid editing logic. Use onEditorPreparing instead. There, you can save the default onValueChanged code and execute it after your code.

Please let me know if you need any clarification.

Regards,
Romeo

    Comments (2)
    XG XG
    Xavier Gutierrez 1 3 years ago

      Ty!

      Solved

      This is the code that i used:

      Razor
      .OnEditorPreparing(@"function(e) { if (e.dataField === 'ManualRequestsForCollections' && e.parentType === 'dataRow') { const defaultValueChangeHandler = e.editorOptions.onValueChanged; e.editorOptions.onValueChanged = function(args) { ShowManualRequestsForCollectionsDialog(); defaultValueChangeHandler(args); } } }") <script> function ShowManualRequestsForCollectionsDialog() { var myDialog = DevExpress.ui.dialog.custom({ showTitle: false, messageHtml: "¡Recuerde que este cambio solo afecta a los nuevos envases y que los usuarios de las PDA's deben volver a inicar sesión para que los cambios tengan efecto!", buttons: [ { text: "Aceptar", onClick: function (b) { return { buttonText: b.component.option("text") } } }] }); myDialog.show(); } </script>
      DevExpress Support Team 3 years ago

        I’m happy to help.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.