Grid Edit send values to controller

Hi,

I have a grid that lists my products. The columns are ProductCode, Description, Price and QtyToOrder.

The QtyToOrder column is rendered with a default value of zero.

I need the following:

  1. Only the QtyToOrder column must be editable
  2. On button click, I must send the grid data (only where the QtyToOrder is not 0) off to the controller.
Below is my view code.

<div class="container-fluid">

    <h4 class="h4">Select Products to Order</h4>

    <div id="dataGrid">

        @Html.EJS().Grid("products").DataSource((IEnumerable<object>)ViewBag.products).Width("auto").Height("auto").Columns(col=>

   {

       col.HeaderText("Picture").Template("#template").Add();

       col.Field("ProductCode").HeaderText("Product Code").IsPrimaryKey(true).Add();

       col.Field("Description").HeaderText("Description").Add();

       col.Field("Price").HeaderText("Unit Price").Add();

       col.Field("QtyToOrder").HeaderText("Qty To Order").Add();

   }).Height("700px").EditSettings(edit => { edit.AllowEditing(true).AllowAdding(false).AllowDeleting(false).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Render()

    </div>

</div>

<style>

    .image img {

        height: 55px;

        width: 55px;

        border-radius: 10px;

        box-shadow: inset 0 0 1px #e0e0e0, inset 0 0 14px rgba(0, 0, 0, 0.2);

    }

</style>


<script id="template" type="text/x-template">

    <div class="image">

        <img src="/Content/Images/${ProductCode}.jpg" alt="${ProductCode}" />

    </div>

</script>



3 Replies 1 reply marked as answer

EW Eddie Willcox September 27, 2021 11:48 AM UTC

I have added .AllowEditing(false) for all columns except the ProductCode and QtyToOrder columns. This takes care of the first requirement.


Now I still need the following:

  1. On button click, I must send the grid data (only where the QtyToOrder is not 0) off to the controller.
  2. Start editing on single click. I currently need to double click a row to start the editing Edit: This is now resolved


EW Eddie Willcox September 27, 2021 03:05 PM UTC

From documentation, I was able to get only the rows where the QtyToOrder was not 0. I used the gridobject.

getBatchChanges().changedRecords to grab only where a qty was filled in. This then sends only those rows to the controller and from vontroller I can now do what I need to with teh grid data.


Marked as answer

JC Joseph Christ Nithin Issack Syncfusion Team September 28, 2021 11:56 AM UTC

Hi Eddie, 

  Greetings from Syncfusion support. 

  We are glad that you have achieved your requirement with the help of the documentation. 

  Please get back to us if you need further assistance. 

Regards, 
Joseph I. 


Loader.
Up arrow icon