jqxGrid source 的增刪改 API介紹
jqxGrid source addrow
/**
* jqxGrid source 增加一列
* @param rowid 增加列的id
* @param rowdata 增加列的數(shù)據(jù)
* @param position addrow通過position可以接受一個函數(shù)(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() //調(diào)用下面的fun方法
commit(true);
},
按鈕觸發(fā)
// create new row.
$("#addrowbutton").on('click', function () {
var datarow = generaterow();
function fun(){todo}
/**
* 通過addrow匹配source中的addrow方法驼唱,null不傳部服,則默認接收rowId,datarow躏筏,row數(shù)據(jù)鳍悠,fun,方法
* @type {*|{scripts, deps}|jQuery}
*/
var commit = $("#grid").jqxGrid('addrow', null, datarow,fun);
});
jqxGrid source deleterow
通過jqxGrid source刪除一行數(shù)據(jù)号涯,通常需要選擇一行合砂,然后獲取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);
},
按鈕觸發(fā)
// 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大致相同微猖,只不過取消了回調(diào)函數(shù)
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);
}