我试图获得一个jQuery的jqgrid启动和运行的实现。一切都很顺利,除了saveCell函数我试着打电话。我希望我的插件可以随时编辑任何* _fee字段,我希望小计和总字段也能自动更新。我已经使用getCell和setCell进行了视觉更新工作,但saveCell无法正常工作。 saveCell()实际上并没有将字段数据传递给我的PHP脚本。已编辑的费用字段的初始保存工作正常,但小计字段和总字段自动切换后的ajax请求尚未完成。我得到id和oper字段,但不是我实际改变的字段!jqgrid saveCell问题
这里是我的代码:
$("#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请求不要不包含实际更改的字段数据,我无法保存!有没有人有这个提示?谢谢!
奥列格,那么你会怎么做呢?我希望小计和总字段在更新任何* _fee字段时自动更新和保存。有没有不同的方法,我应该使用,而不是saveCell?或者我应该有一个完全不同的策略? – Erreth
@Erreth:您应该只使用[jQuery.ajax](http://api.jquery.com/jQuery.ajax/)或一些简化形式,如[jQuery.post](http://api.jquery.com/ jQuery.post /)发送任何数据到服务器。所以我建议你将'setCell'后的'saveCell'调用替换为'$ .ajax'或'$ .post'。 – Oleg