I am facing an issue in Inline editing, I have a jqGrid with pager. If the user changes the value of three cells suppose. After editing the third cell the user clicks on the next page button of the jqGrid pager. Now when the user returns back to the first page, only the changed values of the first two cells are retained and the third is lost. Please suggest how to retain the values of all the cells..?
Sample Code:
var mydata = [{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
},{
name: "Toronto",
country: "Canada",
continent: "North America"
}, {
name: "New York City",
country: "USA",
continent: "North America"
}, {
name: "Silicon Valley",
country: "USA",
continent: "North America"
}, {
name: "Paris",
country: "France",
continent: "Europe"
}]
$("#grid").jqGrid({
data: mydata,
datatype: "local",
colNames: ["Name", "Country", "Continent"],
colModel: [{
name: 'name',
index: 'name',
editable: true,
}, {
name: 'country',
index: 'country',
editable: true,
}, {
name: 'continent',
index: 'continent',
editable: true,
}],
rowNum: 10,
pager: '#pager',
'cellEdit': true,
'cellsubmit' : 'clientArray',
editurl: 'clientArray'
});
It's wrong to use
cellEdit: true
if you want to use inline editing. On the other side to use inline editing you have to start inline editing, for example you can starteditRow
inside ofonSelectRow
callback (see the documentation). So the code which you posted just ignoresediturl: 'clientArray'
and it works like pure cell editing.The main problem which you have is unsaved data on paging. To solve the problem you need just call explicitly saveCell method inside of onPaging callback. The parameters
iRow
andiCol
required forsaveCell
you can get as the property of the standard jqGrid options (usinggetGridParam
method). The corresponding code can be line below:The next potential problem in your code: the data are not full. The input data should contains
id
property to identify every item of input data. The array of input data contains for example multipleToronto
items. It could be just a problem in your test input. The data can be displayed in the grid in sorted form, so to it will be difficult to distinguish the items. It's strictly recommended to haveid
property assigned. You can get the modified data later using$("#grid").jqGrid("getGridParam", "data")
and compare items with original data based on the id to see which one were changed.I suggest that you add unique
id
property to every item. It could be for example 1,2,3 or 10,20,30 or something like that. The corresponding modified code is below. I added some options to jqGrid too. You can run the code and verify that the problem with unsaved data during paging is solved.