最后,我设法制定了一部法典,以发现我们想要的东西。
希望那里的任何支电网格(如Oleg)有足够的时间审查这一守则并改进。
示范守则将努力在网格中检测数据,并有一个名为的可编辑领域。 如果你想在更多的栏目中核对变化的数据,就必须加上与该栏相协调的“<代码>后”的变量。
为了在<代码>on SelectRow功能中获取先前的手机数据,我没有使用getCell
方法,因为在文件中,红字显示:
Do not use this method when you editing the row or
cell. This will return the cell content and not the
actuall value of the input element
By disgrace I could check that the documentation was right :(.
However the getCell
function works properly with the current cell data.
这里是法典:
// Declare variables used for inline edit functionality.
var last_selected;
var before_edit_value;
var after_edit_value;
$( #grid-id ).jqGrid({
...
onSelectRow: function(row_id){
if(row_id && row_id !== last_selected) {
/*
* Determine if the value was changed, if not there is no need to save to server.
*/
if (typeof(last_selected) != undefined ) {
after_edit_value = $( #grid-id tr# + last_selected + .name_column input ).val();
}
if (before_edit_value != after_edit_value) {
/*
* Save row.
*/
$( #grid-id ).jqGrid(
saveRow ,
last_selected,
function(response){
/* SuccessFunction: Do something with the server response */
return true;
},
http://url.to.server-side.script.com/server-side-script.php ,
{
additional_data: example: additional string ,
});
}
else {
/*
* Restore the row.
*/
$( #grid-id ).jqGrid( restoreRow , last_selected);
}
before_edit_value = $( #grid-id ).jqGrid( getCell , row_id, name );
}
last_selected = row_id;
/*
* Edit row.
*/
$( #grid-id ).jqGrid(
editRow ,
row_id,
true,
function() {/* OnEditFunction */},
function(response) {
/* SuccessFunction: Do something with the server response */
return true;
},
http://url.to.server-side.script.com/server-side-script.php ,
{
additional_data: example: additional string ,
});
},
...
});