【问题标题】:Unexpected behavior in jqGrid when trying to setRowData尝试 setRowData 时 jqGrid 中的意外行为
【发布时间】:2015-05-29 22:07:36
【问题描述】:

我正在处理一项需要更新 jqgrid 中的整行数据的任务。

这是一个 fiddler 示例:https://jsfiddle.net/99x50s2s/47/

在上面的fiddler中,请更新一行,然后尝试向右滚动。

代码:

var $thisGrid = jQuery("#sg1");
$thisGrid.jqGrid({
    datatype: "local",
    gridview: true,
    loadonce: true,
    shrinkToFit: false,
    autoencode: true,
    height: 'auto',
    width: 400,
    viewrecords: true,
    sortorder: "desc",
    scrollrows: true,
    loadui: 'disable',
    colNames:["", 'Inv No', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {
            name: "Symbol", index: "Symbol", width: 70, align: 'center', frozen: true,
                formatter: function (cellValue, options, rowObject) {
                    return '<button class="btn btn-info btn-xs update" type="button" title="Update" >' +
                            '<span class="glyphicon glyphicon-remove-circle"></span> Update</button>';
                }
            },
        {name:'id',width:60, sorttype:"int"},   
        {name:'name', width:100},
        {name:'amount', width:80, align:"right",sorttype:"float"},
        {name:'tax', width:80, align:"right",sorttype:"float"},     
        {name:'total', width:80,align:"right",sorttype:"float"},        
        {name:'note', width:150}        
    ],
    caption: "Test Data",
        onCellSelect: function (rowid,
        iCol,
        cellcontent,
        e) {
            if (iCol == 0) {
                var newdata = [
                {id:"1",name:"new test1 name for testing purpose",note:"new note1",amount:"500.00",tax:"50.00",total:"510.00"},    
                ];
                $thisGrid.jqGrid('setRowData', rowid, newdata[0]);
            }               
        }
}).jqGrid('setFrozenColumns');

var mydata = [
    {id:"1",name:"test1",note:"note1",amount:"200.00",tax:"10.00",total:"210.00"},
    {id:"2",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
    {id:"3",name:"test3",note:"note3",amount:"400.00",tax:"25.00",total:"360.00"},
    {id:"4",name:"test4",note:"note4",amount:"500.00",tax:"60.00",total:"350.00"},
    {id:"5",name:"test5",note:"note5",amount:"600.00",tax:"70.00",total:"340.00"}
        ];

for(var i=0;i<=mydata.length;i++)
    $thisGrid.jqGrid('addRowData',i+1,mydata[i]);

我想知道如何解决此问题?任何帮助表示赞赏。

注意:

jqGrid 版本:4.6.0 已应用:冻结列和单元格文本换行。

编辑:

从提琴手拍摄的带有解决方案的快照:

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

    我过去已经写信告诉你,4.6.0 版不支持编辑带有冻结列的网格。

    要使代码正常工作,每次更改网格内容后都必须做很多事情。必须调整冻结 div 的位置,并明确设置冻结 div 中每一行的高度和宽度。您可以从代码中找到必须使用herehere 的示例。

    现在有更简单的解决方案。如果只是将jqGrid 4.6版本替换为github上的免费jqGrid的当前一种代码

    <link href="https://rawgit.com/free-jqgrid/jqGrid/master/css/ui.jqgrid.css" rel="stylesheet"/>
    <script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/i18n/grid.locale-en.js"></script>
    <script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>
    

    然后您的代码开始按预期工作:https://jsfiddle.net/OlegKi/99x50s2s/48/

    因此,您可以自己做很多事情,也可以获取已经这样做的代码。

    【讨论】:

    • 之前我试图只编辑冻结的单元格,但现在是整行。但是,你的回答很有道理……
    • 我在您提供的提琴手中发现了一个小问题。尝试挤压一列并查看冻结列的行为...看起来重复的按钮出现在冻结列中。
    • @VimalanJayaGanesh:抱歉,我可能不明白你的意思。我无法重现任何问题。此外,如果列的内容是固定的(如按钮的宽度),建议使列不可调整大小。所以最好将resizable: false 添加到第一列。如果确实存在问题,请更准确地描述测试用例。
    • Oleg,我已经用快照和重现问题所涉及的步骤更新了问题。
    • @VimalanJayaGanesh:感谢您的错误报告。我删除了用于调整大小的旧的不需要的事件处理程序,现在将使用新的处理程序(请参阅the fix)。请重试相同的演示。它使用来自 GitHub 的源代码,现在可以正常工作了。
    猜你喜欢
    • 2019-07-09
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    相关资源
    最近更新 更多