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

Update row JS grid

I have this JS:
var dm = ej.DataManager({
url: "/Home/get", crossDomain: true,
updateUrl: '/Home/update',
adaptor: new ej.UrlAdaptor()
});
$("#Grid").ejGrid({
dataSource: dm,
filterSettings: {
filterType: "menu"
},
pageSettings: { enableQueryString: true, pageSize: 10 },
toolbarSettings: { showToolbar: true, toolbarItems: ["add", "edit", "delete", "update", "cancel", "search"] },
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },
columns: [
{ field: "data", headerText: "Data", isPrimarykey: true },
{ field: "value", headerText: "Value" },
]
});
which creates grid. If I try to change info in some row it sends update request to the given URL, which is JSON value .
How to catch the value parameter on the server ?
How can I send another parameter like id of the row data which is updated?

5 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 5, 2017 08:36 AM UTC

Hi Customer,  
 
Thanks for contacting Syncfusion Support.  
 
Query #1: How to catch the value parameter on the server ? 
 
We could see you are looking for the CRUD action handlers in the Grid with required parameters. Refer to the following code example and Help Document. 
 
        public ActionResult Update([FromBody]CRUDModel<Project> myObject) 
        { 
            var updateData = myObject.Value; 
            . ..  
               . . . 
            return Json(myObject.Value);             
        } 
 
 
Query #2: How can I send another parameter like id of the row data which is updated? 
 
We recommend to pass the value of the primary key to the server end, for updating the values to the database. This can be achieved by using the custom headers of the DataManager. We have already discussed about this in the following Kb.  
 
 
The ID value sent to the server end using the custom headers has been used to retrieve the records of the parent Grid and from there we have traversed current slave Grid’s record. Refer to the following code example.  
 
        public ActionResult CellEditInsertDetail([FromBody]CRUDModel<AlarmModel> value) 
        { 
            int readonlyID = int.Parse(Request.Headers["ID"]); 
            return Json(value.Value); 
        } 
 
            $("#Grid").ejGrid({ 
                dataSource: ej.DataManager({ 
                    url: "/Home/DataSource", 
                    updateUrl: "/Home/Update", 
                    adaptor: new ej.UrlAdaptor() 
                }), 
                actionBegin: function (args) { 
                    if (args.requestType == "save") 
                        this.model.dataSource.dataSource.headers = [{ ID: args.rowData.OrderID }]; 
                }, 
                . ..  
            }); 
 
Regards,  
Seeni Sakthi Kumar S. 



NO noName September 5, 2017 03:54 PM UTC

Hi, thanks It works. Just one thing. For now I am not using headers for ID, but I get Id from:

[FromBody]CRUDModel<Project> myObject

with:

Guid ID = Guid.Parse(myObject.Key.ToString());

, because The ID is there when I check in the console:

  1. Recuest headers:
  2. field:
    ID
  3. Host:
    localhost:23180
  4. IsValid:
    true

, but when I try to get it like this:

int readonlyID = int.Parse(Request.Headers["ID"]); 

it is null.

Other thing is for the insert I am using same param:

public IActionResult Create([FromBody]CRUDModel data)

, but data is null. I see from the console it is send to the server.



SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 6, 2017 05:26 AM UTC

Hi Customer,  
 
Query #1: Custom Headers is null 
 
We suspect that you are not sending value as shown in our previous example. Please refer to the following code example and output.  
 
        public ActionResult CellEditInsertDetail([FromBody]CRUDModel<AlarmModel> value)  
        {  
            int readonlyID = int.Parse(Request.Headers["ID"]);  
            return Json(value.Value);  
        }  
  
            $("#Grid").ejGrid({  
                dataSource: ej.DataManager({  
                    url: "/Home/DataSource",  
                    updateUrl: "/Home/Update",  
                    adaptor: new ej.UrlAdaptor()  
                }),  
                actionBegin: function (args) {  
                    if (args.requestType == "save")  
                        this.model.dataSource.dataSource.headers = [{ ID: args.rowData.OrderID }];  
                },  
                . ..   
            }); 
 
 
 
Query #2: Insert Operation not receiving the data 
 
We could see the absence of Model Class in the parameter which might cause this problem. So, we suggest reframe your code as follows.  
 
 
        public ActionResult Insert([FromBody]CRUDModel<Project> myObject)  
        {  
            return Json(myObject.Value);              
        } 
 
 
Regards,  
Seeni Sakthi Kumar S. 



NO noName September 6, 2017 03:34 PM UTC

Hi, thx, Query 1 is fixed.

About Query 2, yes I set the model name here [FromBody]CRUDModel<ModelName> myObject.

, but myObject is still null. What I do is exact: [FromBody]CRUDModel<Object> data, Object, but not Model name and now everything works. 




SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 7, 2017 04:54 AM UTC

Hi Jim,  
 
Thanks for the update.  
 
We are happy to hear that your problem has been resolved. Please get back to us, if you require further assistance on this. 
 
Regards, 
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon