As you can see, I’m very new to this stuff.
I have set up a jqGrid, in loads fine. I’m trying to enable inline editing, and I’m not sure how to set things up. My receiving method is called, but I dont get any data in.
The grid setup:
$(function () {
var lastsel;
$("#list").jqGrid({
url: '@Url.Action("ExampleData", "Home")',
datatype: 'json',
mtype: 'GET',
colNames: ['Namn', 'Adress', 'Stad'],
colModel: [
{ name: 'Name', index: 'Name', width: 130, editable: true },
{ name: 'Address', index: 'Address', width: 180, editable: true },
{ name: 'City', index: 'City', width: 80, editabel: true },
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'Name',
sortorder: 'desc',
viewrecords: true,
gridview: true,
width: 700,
onSelectRow: function (id) {
if (id && id !== lastsel) {
jQuery('#list').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('editRow', id, true);
lastsel = id;
}
},
editurl: '@Url.Action("Incoming", "Home")',
caption: 'Kontaktpersoner'
});
jQuery("#list").jqGrid('navGrid',"#prowed3",{edit:false,add:false,del:false});
And code in the Controller, which gets called. I suppose that is the editurl that should be used for getting data back…
public ActionResult Incoming(Object stuff)
{
return null;
}
Should’nt I get json back to the server, like the stuff I send into it when it’s loaded?
The controller action
Incomingdon’t require to return any data back to the jqGrid because you use it only for editing and not to add new data. It’s important only that in case of error the action returns HTTP status code which corresponds to an error. In the case jqGrid can restore the previous results.In some situation you do should returns data from the server in case of successful editing too. For example, I use typically create non-nullable rowversion (earlier timestamp) column in every table of the database to manage optimistic concurrency. The value for the column will be automatically created on INSERT in the table and be automatically updated at the UPDATE of the data item. So I fill jqGrid with one additional hidden column which I get from the database together with the other data. On row editing the old value of the
rowversionwill be used to verify whether the data are changed from another place. In any way one need to send the new version of therowversionto the jqGrid after any row editing. One can useaftersavefuncto read the server response and to update the value of therowversionsaved in jqGrid.The above explanation is only a rough schema of the possible implementation. The answer on your main question was: you don’t need return anything from the
Incomingaction. If you do need to send some information to jqGrid you can useaftersavefuncparameter of editRow to get the server response and to process it.