hi iam use free jqGrid 4.15.1
i want btn click get all change rows for exmaple 3 row edit 2 row insert 1 row deleted iam use this code i want tish result insert this row
i insert new this tree row
{ id: "gridad", Name: "Name 4", PackageCode: "83123a", other: "x",> },
{ id: "gridadd", Name: "Name 5", PackageCode: "834", other: "x", > },
{ id: "gridadd", Name: "Name 6", PackageCode: "83566a", other: "z", }
edit this row
> { id: "10", Name: "Name 122", PackageCode: "83566a1000", other: "z",
> }
delete this row
> { id: "20", Name: "Name 3", PackageCode: "83432a", other: "y"},
this my code
$(function () {
"use strict";
var data = [
{ id: "10", Name: "Name 1", PackageCode: "83123a", other: "x", subobject: { x: "a", y: "b", z: [1, 2, 3]} },
{ id: "20", Name: "Name 3", PackageCode: "83432a", other: "y", subobject: { x: "c", y: "d", z: [4, 5, 6]} },
{ id: "30", Name: "Name 2", PackageCode: "83566a", other: "z", subobject: { x: "e", y: "f", z: [7, 8, 9]} }
],
$grid = $("#packages");
$grid.jqGrid({
data: data,
datatype: "local",
colModel: [
{ name: "PackageCode", width: 110 },
{ name: "Name", width: 300 }
],
pager: "#packagePager",
rowNum: 2,
rowList: [1, 2, 10],
viewrecords: true,
rownumbers: true,
caption: "Packages",
height: "auto",
sortname: "Name",
autoencode: true,
gridview: true,
ignoreCase: true,
});
$grid.jqGrid("navGrid", "#packagePager",
{ add: false, edit: false, del: false }, {}, {}, {},
{ multipleSearch: true, multipleGroup: true });
$grid.jqGrid("filterToolbar", { defaultSearch: "cn", stringResult: true });
});
this button for get all change
$("#customerCodesTableSave").click(function () {
var gridData = myGrid.jqGrid('getRowData');
var postData = JSON.stringify(rowdata);
alert(gridData.length);
alert(postData);
for (var i = 0; i < gridData.length; i++) {
alert(i + "_" + (gridData[i]['id']));
if (gridData[i].id == $(myGrid)[0].id + "_0")
{
alert(gridData[i]['id']);
}
//myGrid.jqGrid('saveRow', gridData[i]['id']);
}
saveGrid();
});
You can use for example aftersavefunc
callback of inline editing and afterComplete
of row deleting to collect the statistic of added, edited and deleted rows. You can hold the statistic in a custom option of jqGrid.
The demo update demo
stat: { // custom option to hold the editing statistics
edit: 0,
add: 0,
del: 0
},
formDeleting: {
afterComplete: function (jqXHR, postdata) {
var p = $(this).jqGrid("getGridParam");
p.stat.del++;
}
},
inlineEditing: {
aftersavefunc: function (rowid, jqXhr, postData, options) {
// postData.oper will be either "add" or "edit"
var p = $(this).jqGrid("getGridParam");
p.stat[postData.oper]++;
}
}
You can get the statistics in the same way like you access to other jqGrid parameters:
$("#getStat").click(function () {
var p = $grid.jqGrid("getGridParam");
alert("added rows: " + p.stat.add + "\n" +
"edited rows: " + p.stat.edit + "\n" +
"deleted rows: " + p.stat.del);
});
Of cause the above code is very simple. You can hold the array with rowids of editing/added and deleted rows instead of just numbers. It will allows you to hold more exact statistic. I mean that the simplest code above will increment stat.edit
if the user will edit the same row multiple times. If the added/edited row will be deleted later then the stat.add
and stat.edit
will be not adjusted. Holding array of rowids in stat.add
, stat.edit
and stat.del
will allow to fix hold more exact statistics.