We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to prevent batch saving when grid columns are invalid

I hava a grid, for which validation rules are added. These rules are checked when the cells are being edited but not before saving. How can i determine which values/cells are invalid, based on the validation rules added to the column. Also, is it possible to force the yellow validation message popups to show when the user clicks the update button, if there are invalid columns? I would like to show validation errors on the client-side and prevent saving if any columns are invalid.

3 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team February 18, 2016 09:29 AM UTC

Hi Debbie,

Thanks for contacting Syncfusion support.

When the cells are being edited and while selecting a row, the edited row will save. If there is any invalid column, the validation message will pop-up. To avoid this, we suggest you to use rowSelecting event of ejGrid. This event triggers before the row going to be selected and we stop the validation message by defining args.cancel as true.  

Please find the code example and sample:


@(Html.EJ().Grid<Sample119799.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        .AllowPaging()    /*Paging Enabled*/

        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

        .AllowSorting()

        .ToolbarSettings(toolbar =>

        {

            toolbar.ShowToolbar().ToolbarItems(items =>

            {

                items.AddTool(ToolBarItems.Add);

                items.AddTool(ToolBarItems.Edit);

                items.AddTool(ToolBarItems.Delete);

                items.AddTool(ToolBarItems.Update);

                items.AddTool(ToolBarItems.Cancel);

            });

        })

        .ClientSideEvents(eve => eve.RowSelecting("action"))

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("CustomerID").HeaderText("Customer ID").ValidationRules(v => v.AddRule("required",true).AddRule("minlength", 3)).Width(80).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").ValidationRules(v => v.AddRule("required",true)).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();

        }))


<script type="text/javascript">

    function action(args) {

     if(this.model.isEdit)

        args.cancel = true;

    }
</script>


Sample : http://www.syncfusion.com/downloads/support/forum/122107/ze/Sample119799-392805097

Refer to the Help document for the rowSelecting event

http://help.syncfusion.com/js/api/ejgrid#events:rowselecting

Regards,
Prasanna Kumar N.S.V



DF Debbie Facey February 18, 2016 09:27 PM UTC

Hi Prasanna,

I think you misunderstood me. Please see attached images as reference.

When I click the Add button to add a new empty row at the top of the grid, then I click the Update button immediately then empty row data is submitted to the server.

What I would like to happen is that, on the client-side, I determine if the rows being submitted are valid. If not, I would like to trigger the validation messages to be displayed below the invalid cells.

So my questions are:

  1.  After the Update button is clicked but before the batch changes are actually submitted, how can I determine the cells that are not valid
  2. If I can determine which cells are not valid, how can i trigger the display of the validation error message below the invalid cell.
Currently the message displays during edit for invalid cells. See second image. I'd like to manually show these messages after the Update button is clicked.

Thanks.

Attachment: Captures_efd40312.zip


PK Prasanna Kumar Viswanathan Syncfusion Team February 19, 2016 09:43 AM UTC

Hi Debbie,

The reported issue “Validation message is not shown while adding new empty record in batch editing” has been reproduced at our end. We have considered it as the defect and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates


https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents 

Regards,
Prasanna Kumar N.S.V


Loader.
Live Chat Icon For mobile
Up arrow icon