javascript - jqgrid getCell 奇怪的行为

标签 javascript jquery jqgrid

我有一个 jqgrid 和一个 getCell 方法,它根据 id 返回单元格的值。它仅适用于网格的第一行,在其他行中identifyImg = false:

var ids = jQuery("#myGrid").getDataIDs(); 
        for(var i=0;i<ids.length;i++){
            var identifyImg = $('#myGrid').jqGrid('getCell', i, 'idState');
alert(identifyImg); // return false after first row
            if(identifyImg == '1'){
                 //DO SOMETHING 
              }
            }

该列定义如下:

{name:'idState',index:'idState', width:55}

并且正确地填充了数字。我该如何解决这个问题?

最佳答案

你应该使用

 $('#myGrid').jqGrid('getCell', ids[i], 'idState');

而不是

 $('#myGrid').jqGrid('getCell', i, 'idState');

我还想提一下,在大多数情况下,不需要对 getDataIDs 返回的 id 使用循环。这是在旧版本 jqGrid 中的 loadCompletegridComplete 中自定义 jqGrid 的好方法。现在有更多更好的(从性能 Angular 来看)替代方案。例如,如果您需要根据一列的内容更改一个单元格的某些样式或其他属性,您可以使用 cellattr (请参阅 the answerthe answerthe answerthe answer或其他)。如果您需要根据一列的内容更改整行的某些属性,您可以使用 rowatr (请参阅 the answer )。在其他情况下,如果您需要根据另一个单元格的内容更改单元格的内容(而不是属性),您可以使用 custom formatter .

关于javascript - jqgrid getCell 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13320742/

相关文章:

javascript - CSS 和 jQuery 通用树形菜单

javascript - Angular 4 : add new td to table with *ngif with modulo in an *ngfor

javascript - 使用日期范围过滤数据表

javascript - Fullcalendar drop外部事件恢复功能

javascript - 将超链接传递和获取到单个 JQuery 函数中

jquery - jqgrid - postData 提交之前的请求参数和数据

javascript - 如何在 multer 中上传带有可选数据的图像?

javascript - 未捕获的 TypeError : Masonry. init 不是函数

c# - ASP.NET MVC $.post 调用返回字符串...需要有关 jqGrid 格式的帮助

jquery - 在行之前但在表格之外添加元素?