jqxGrid source 的增删改 API介绍
jqxGrid source addrow
/**
* jqxGrid source 增加一列
* @param rowid 增加列的id
* @param rowdata 增加列的数据
* @param position addrow通过position可以接受一个函数(function)
* @param commit true or false 来判断是否增加此列
*/
addrow: function (rowid, rowdata, position, commit) {
// synchronize with the server - send insert command
// call commit with parameter true if the synchronization with the server is successful
// and with parameter false if the synchronization failed.
// you can pass additional argument to the commit callback which represents the new ID if it is generated from a DB.
position() //调用下面的fun方法
commit(true);
},
按钮触发
// create new row.
$("#addrowbutton").on('click', function () {
var datarow = generaterow();
function fun(){todo}
/**
* 通过addrow匹配source中的addrow方法,null不传,则默认接收rowId,datarow,row数据,fun,方法
* @type {*|{scripts, deps}|jQuery}
*/
var commit = $("#grid").jqxGrid('addrow', null, datarow,fun);
});
jqxGrid source deleterow
通过jqxGrid source删除一行数据,通常需要选择一行,然后获取rowid,在进行删除,其余跟addrow相同。
deleterow: function (rowid, commit) {
// synchronize with the server - send delete command
// call commit with parameter true if the synchronization with the server is successful
//and with parameter false if the synchronization failed.
commit(true);
},
按钮触发
// delete row.
$("#deleterowbutton").on('click', function () {
//获取选中行
var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex');
//获取总共有几行
var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount;
if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
//获取选中行的id
var id = $("#grid").jqxGrid('getrowid', selectedrowindex);
ar commit = $("#grid").jqxGrid('deleterow', id);
}
});
jqxGrid source update
jqxGrid source update与addrow大致相同,只不过取消了回调函数
updaterow: function (rowid, newdata, commit) {
// synchronize with the server - send update command
// call commit with parameter true if the synchronization with the server is successful
// and with parameter false if the synchronization failed.
commit(true);
}
网友评论