weixin_33693070 2011-09-30 21:55 采纳率: 0%
浏览 75

如何用SaveCell得到实际更改的字段?

我正在尝试让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请求不包含实际更改的字段数据,因此无法保存! 有人有什么建议吗?谢谢!

  • 写回答

1条回答 默认 最新

  • 斗士狗 2011-09-30 22:26
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料