jqgrid saveCell问题
我正在尝试启动并运行 jquery 的 jqgrid 的实现。一切都很顺利,除了我试图调用的 saveCell 函数。我希望我的插件做的是每当编辑任何 *_fee 字段时,我希望小计和总计字段也能自动更新。我已经使用 getCell 和 setCell 进行了视觉更新,但 saveCell 无法正常工作。 saveCell() 实际上并没有将字段数据传递给我的 php 脚本。编辑后的费用字段的初始保存工作正常,但自动更改小计和总计字段时的后续 ajax 请求未完成。我得到了 id 和 oper 字段,但没有得到我实际更改的字段!
这是我的代码:
$("#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'm trying to get an implementation of jquery's jqgrid up and running. All is going well, except for the saveCell function I'm tryin to call. What I want my plugin to do is anytime any of the *_fee fields are edited, I want the subtotal and total fields to autoupdate as well. I've got the visual updating working using getCell and setCell, but the saveCell isn't functioning correctly. saveCell() doesn't actually pass the field data to my php script. The initial saving of the edited fee field works perfectly, but subsequent ajax request when the subtotal and total fields are autochanged is not complete. I get the id and the oper fields, but not the field I actually changed!
Here is my code:
$("#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,
},
{}
);
});
The first ajax request contains:
Array
(
[trans_fee] => 15.13
[id] => 1
[oper] => edit
)
But the subsequent ajax request only contains:
Array
(
[id] => 1
[oper] => edit
)
Because the subsequent ajax request don't contain the actual changed field data, I can't save it! Does anyone have tips with this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为存在误解 saveCell 方法的作用。它只能与 editCell 一起使用,并且不能仅用于将某些单元发送到服务器。调用 [editCell] 后,单元格的当前内容将保存在内部 savedRow 参数。将创建输入字段,用户可以更改单元格内容。如果稍后调用 saveCell 方法 savedRow 参数将与当前单元格进行比较 内容。如果存在差异,则更改将发送到服务器。
因此,您尝试以错误的方式使用 saveCell 方法。您无法发送之前使用
setCell
方法更改的新单元格值。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.