jqGrid setRowData方法不会更新隐藏的行 [英] jqGrid setRowData method doesn't update hidden rows

查看:215
本文介绍了jqGrid setRowData方法不会更新隐藏的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqGrid的filterToolbar方法让用户快速搜索/过滤网格数据.我正在使用loadonce: truedatatype: local作为我的网格配置.我的其中一列有一个下拉(选择)过滤器类型,可以正常工作.

I'm using jqGrid's filterToolbar method to let users quick search/filter the grid data. I'm using loadonce: true and datatype: local as my grid configs. I have a drop-down (select) filter type for one of my columns, which works fine.

问题是当我尝试更新不可见的行(使用setRowData)时(由于过滤器/搜索结果隐藏了它们),当我通过清除过滤器重新显示它们时,该行没有得到更新.

Problem is when i try to update a row (using setRowData) that is not visible (because the filter/search result is hiding them), the row doesn't get updated when I reshow them by clearing the filter.

有什么建议吗?我也尝试过触发reloadGrid事件,没有运气.

Any suggestions? I've tried triggering the reloadGrid event too, no luck.

欢呼

以下是使用jqGrid的官方演示来重现该问题的方法:

Here's how to reproduce the problem, using jqGrid's official demos:

浏览到jqGrid的演示页面,并在"3.7版的新功能"下打开名为工具栏搜索"的演示.

Browse to the jqGrid's demo page, and open the demo named 'Toolbar search' under 'New in version 3.7'

在演示网格中,按代码列的值575878进行过滤,以便网格中仅显示第一行.

In the demo grid, filter by the code column with the value 575878 so that only the first row is shown on the grid.

启动JavaScript控制台并更新当前不可见的行,在此示例中,更新第2行: jQuery("#toolbar").jqGrid('setRowData',2,{item_id:2,item:'blargh',item_cd:12345678});

Bring up the javascript console and update a row that's not currently visible, in this example update row 2: jQuery("#toolbar").jqGrid('setRowData',2,{item_id:2,item:'blargh',item_cd:12345678});

通过清除过滤器值取消隐藏所有行,并查看第2行尚未更新!

Unhide all the rows by clearing the filter value, and see that row 2 has not been updated!

我在这里做错什么了吗?可能的解决方法?

Anything I'm doing wrong here? Possible workarounds?

推荐答案

您误解了网格的构建方式.网格可以包含隐藏的列,但没有隐藏的行.如果是一个过滤器网格,则将删除整个网格主体,并且仅插入经过过滤的行.

You misunderstand how the grid are build. Grid can contain hidden columns, but no hidden rows. If one filter grid the full grid body will be removed and only the filtered rows will be inserted.

方法setRowData可用于修改网格的任何行,但不能修改网格中不存在的内容.

The method setRowData can be used to modify any row of the grid, but you can't modify something which is not present in the grid.

如果使用本地网格(datatype: 'local'),则保存在网格中的数据将保存在两个内部jqGrid参数data_index中.因此,您应该修改data对象.要使用修改后的data填充网格,您需要调用.trigger("reloadGrid").

If you use local grid (datatype: 'local') then the data which you save in the grid will be saved in two internal jqGrid parameters data and _index. So you should modify the data object. To fill grid with modified data you need call .trigger("reloadGrid").

因此,如果要修改rowid = 2的网格数据的列item_iditemitem_cd,则可以执行以下步骤.

So if you want modify columns item_id, item and item_cd of the grid's data for the rowid=2 you can do the following steps.

1)获取对内部jqGrid参数data_index的引用:

1) Get references to the internal jqGrid parameters data and _index:

var $myGrid = jQuery("#toolbar"),
    data = $myGrid.jqGrid('getGridParam', 'data'),
    index = $myGrid.jqGrid('getGridParam', '_index');

2)获取对表示您需要的rowid的对象的引用:

2) Get reference to the object which represent the rowid which you need:

var rowId = '2',
    itemIndex = index[rowId],
    rowItem = data[itemIndex];

3)根据需要修改数据项:

3) Modify the data item like you as need:

rowItem.item_id = 2;
rowItem.item = 'blargh';
rowItem.item_cd = 12345678;

4)通过重新加载网格来刷新网格包含(如果需要)

4) Refresh grid contain (if needed) by reloading the grid

$myGrid.trigger('reloadGrid');

这篇关于jqGrid setRowData方法不会更新隐藏的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆