我正在尝试让jQuery的jqGrid实现并运行起来。一切都进行得很好,除了我正在尝试调用的saveCell功能。我想要我的插件做的是:任何时候,任何_fee字段被编辑了,小计和总字段都能够自动刷新。我已经使用getCell和setCell进行了可视化更新,但是SaveCell还是无法正常工作:SaveCell()并没能将字段数据传递给php脚本。而且,即使编辑字段的初始保存工作良好,但当小计字段和总字段自动更改时,后续Ajax请求仍未完成。我只得到了ID和操作字段,但得不到实际更改的字段!
代码如下:
$("#cust_grid").jqGrid({
url:'/ajax/grid',
datatype: 'xml',
mtype: 'POST',
colNames:['ID','Company', 'Sales','Credits','Voids','Declines','Total Trans','Monthly Fee','Trans Fee','Misc Fee','Subtotal','Total'],
colModel :[
{name:'id', index:'id', width:55, search: true},
{name:'company', index:'company', width:100, search: true},
{name:'sales', index:'sales', width:70, search: true},
{name:'credits', index:'credits', width:70, search: true},
{name:'voids', index:'voids', width:70, search: true},
{name:'declines', index:'declines', width:70, search: true},
{name:'total_trans', index:'total_trans', width:70, align:'right', search: true},
{name:'monthly_fee', index:'monthly_fee', width:90, align:'right', editable: true, search: true, formatter: 'number'},
{name:'trans_fee', index:'trans_fee', width:70, align:'right', editable: true, search: true, formatter: 'number'},
{name:'misc_fee', index:'misc_fee', width:70, align:'right', editable: true, search: true, formatter: 'number'},
{name:'subtotal', index:'subtotal', width:90, align:'right', search: true},
{name:'total', index:'total', width:90, align:'right', search: true}
],
pager: '#pager',
rowNum:25,
rowList:[10,25,50,100],
sortname: 'id',
sortorder: 'asc',
viewrecords: true,
gridview: true,
caption: 'Our Customers',
height: 600,
altRows: true,
cellEdit: true,
cellsubmit: "remote",
cellurl: "/ajax/editCell",
afterSaveCell: function (rowid, cellname, value, iRow, iCol) {
var transFee = $('#cust_grid').jqGrid('getCell', rowid, 'trans_fee');
var totalTrans = $('#cust_grid').jqGrid('getCell', rowid, 'total_trans');
var subtotal = transFee * totalTrans;
subtotal = subtotal.toFixed(2);
//alert(subtotal);
var monthlyFee = $('#cust_grid').jqGrid('getCell', rowid, 'monthly_fee');
//alert(monthlyFee);
var total = Number(subtotal) + Number(monthlyFee);
//alert(total);
total = total.toFixed(2);
$('#cust_grid').jqGrid('setCell', rowid, 'subtotal', subtotal);
alert("iRow=" + iRow + " iCol=" + iCol);
$('#cust_grid').jqGrid('saveCell', iRow, 10);
alert("cell saved!");
$('#cust_grid').jqGrid('setCell', rowid, 'total', total);
$('#cust_grid').jqGrid('saveCell', iRow, 11);
}
});
$("#cust_grid").jqGrid('navGrid','#pager',
{edit:false,add:false,del:false,search:true},{},{},{},
{
closeAfterSearch:true,
closeOnEscape:true,
},
{}
);
});
第一个ajax请求包含:
Array
(
[trans_fee] => 15.13
[id] => 1
[oper] => edit
)
但是后续的ajax请求仅包含:
Array
(
[id] => 1
[oper] => edit
)
由于后续的ajax请求不包含实际更改的字段数据,因此无法保存! 有人有什么建议吗?谢谢!
I think there are misunderstanding what saveCell method do. It works only together with editCell and can't be used just for sending of some cell to the server. After you call [editCell] the current content of the cell will be saved in the internal savedRow parameter. The input field will be created and the user are able to change the cell content. If one later call saveCell method the content of savedRow parameter will be compared with the current cell content. If there are differences then the changes will be sent to the server.
So you try to use saveCell method in a wrong way. You can't send the new cell value which you changed before with respect of setCell
method.