如何使用 btn 单击获取 jqgrid 中的所有行更改 crud
how get all row change crud in jqgrid with btn click
您好,我使用免费的 jqGrid 4.15.1
我想要 btn 单击获取所有更改行,例如
3行编辑
2行插入
删除了 1 行
我正在使用这段代码,我想要 tish 结果插入这一行
我插入新的树行
{ 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", }
编辑此行
> { id: "10", Name: "Name 122", PackageCode: "83566a1000", other: "z",
> }
删除这一行
> { id: "20", Name: "Name 3", PackageCode: "83432a", other: "y"},
这是我的代码
$(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 });
});
此按钮用于获取所有零钱
$("#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();
});
您可以使用例如aftersavefunc
行内编辑回调和afterComplete
行删除回调来收集添加、编辑和删除行的统计信息。您可以将统计信息保存在 jqGrid 的自定义选项中。
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]++;
}
}
您可以像访问其他 jqGrid 参数一样获取统计信息:
$("#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);
});
当然上面的代码很简单。您可以使用 editing/added 的 rowids 和删除的行来保存数组,而不仅仅是数字。它将允许您掌握更准确的统计数据。我的意思是,如果用户多次编辑 相同的 行,上面最简单的代码将递增 stat.edit
。如果稍后删除 added/edited 行,则不会调整 stat.add
和 stat.edit
。在 stat.add
、stat.edit
和 stat.del
中保存 rowid 数组将允许修复保存更准确的统计信息。
您好,我使用免费的 jqGrid 4.15.1
我想要 btn 单击获取所有更改行,例如 3行编辑 2行插入 删除了 1 行 我正在使用这段代码,我想要 tish 结果插入这一行
我插入新的树行
{ 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", }
编辑此行
> { id: "10", Name: "Name 122", PackageCode: "83566a1000", other: "z",
> }
删除这一行
> { id: "20", Name: "Name 3", PackageCode: "83432a", other: "y"},
这是我的代码
$(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 });
});
此按钮用于获取所有零钱
$("#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();
});
您可以使用例如aftersavefunc
行内编辑回调和afterComplete
行删除回调来收集添加、编辑和删除行的统计信息。您可以将统计信息保存在 jqGrid 的自定义选项中。
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]++;
}
}
您可以像访问其他 jqGrid 参数一样获取统计信息:
$("#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);
});
当然上面的代码很简单。您可以使用 editing/added 的 rowids 和删除的行来保存数组,而不仅仅是数字。它将允许您掌握更准确的统计数据。我的意思是,如果用户多次编辑 相同的 行,上面最简单的代码将递增 stat.edit
。如果稍后删除 added/edited 行,则不会调整 stat.add
和 stat.edit
。在 stat.add
、stat.edit
和 stat.del
中保存 rowid 数组将允许修复保存更准确的统计信息。