I've implemented a jqgrid with inline edit:
var lastSel;
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/Home/DynamicGridData/',
datatype: 'json',
mtype: 'POST',
colNames: ['Actions', 'Id', 'note', 'tax'],
colModel: [
{name:'act',index:'act',width:55,align:'center',sortable:false,formatter:'actions',
formatoptions:{
keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing.
onEdit:function(rowid) {
alert("in onEdit: rowid="+rowid+"\nWe don't need return anything");
},
},},
{ name: 'Id', index: 'Id', width: 55,align:'center', editable: false },
{ name: 'note', index: 'note', width: 40,align:'center', editable: true },
{ name: 'tax', index: 'tax', width: 40,align:'center', editable: true}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '',
caption: 'My first grid',
editurl: '/Home/Save/'
});
jQuery("#list").navGrid('#pager', { edit: false, search: false, add: false });
});
The problem is that it's not working as expected. The problem is that when the grid loads the Id data is loaded into the Actions column, the note data is added into the Id column and the tax data is added into the note column. The tax column is empty. I think this is because when the data is loaded there is nothing currently in the Actions column?
Anyway when the actions icon buttons load they load in the Actions column which is correct but over top of the Id data which is in the wrong column.
I've compared this with other working examples but so far have not found the problem.
EDIT:
Have just found this problem occurs with the json data but not local data.
So if you feed it Json data like:
public JsonResult DynamicGridData2(string sidx, string sord, int page, int rows)
{
int totalPages = 1; // we'll implement later
int pageSize = rows;
int totalRecords = 3; // implement later
var jsonData = new {
total = totalPages,
page = page,
records = totalRecords,
rows = new[]{
new {id = 1, cell = new[] {"1", "Note1", "Tax1"}},
new {id = 2, cell = new[] {"2", "Note2", "Tax2"}},
new {id = 3, cell = new[] {"3", "Note3", "Tax3"}}
}
};
return Json(jsonData);
}
The error happens. However if you give it local data like:
data: mydata,
datatype: 'local',
var mydata = [
{id:"1", note:"Note1", tax:"Tax1"},
{id:"2", note:"Note2", tax:"Tax2"},
{id:"3", note:"Note3", tax:"Tax3"}
]
It's fine.