获取jqGrid中的所有行id

时间:2022-06-17 20:10:29

How can one get the ID's of every row in a grid, even across pages?

如何在网格中获取每一行的ID,甚至跨页面?

getDataIDs and getRowData only gives the ID's of the current page.

getDataIDs和getRowData只提供当前页面的ID。

Thanks!

谢谢!

3 个解决方案

#1


13  

It is possible only if you have local grid (datatype:'local' or having loadonce:true). In the case all data inclusive ids for all pages are already locally. In the case you can use _index parameter, which will be used typically together with another more known parameter data. With

只有当您拥有本地网格(datatype:'local'或拥有loadonce:true)时,才可能实现。在这种情况下,所有页面的所有数据包含id都是本地的。在这种情况下,可以使用_index参数,它通常与另一个更已知的参数数据一起使用。与

var idToDataIndex = $("#list").jqGrid('getGridParam','_index');

you will get the _index parameter. It is an object which has as the properties all ids of grid. So you can enumerate the ids with

您将获得_index参数。它是一个具有所有网格id属性的对象。所以你可以用

var id;
for (id in idToDataIndex) {
    if (idToDataIndex.hasOwnProperty(id)) {
        // id is the rowid.
        // to get the data you can use
        // mydata[idToDataIndex[id]] where
        // var mydata = $("#list").jqGrid('getGridParam','data');
    }
}

#2


0  

In later versions of jqGrid they came out with a function that suits this situation better as it will consider any toolbar filtering that may be in place. See Oleg's example here. Thus, if you have a jqGrid (loadonce:true and/or datatype:local) the following will return all row ids (displayed in current page and beyond) which match the current filtering.

在jqGrid的后续版本中,他们提出了一个更适合这种情况的函数,因为它将考虑可能存在的任何工具栏过滤。看到奥列格的例子。因此,如果您有一个jqGrid (loadonce:true和/或datatype:local),下面将返回与当前过滤匹配的所有行id(显示在当前页和其他地方)。

var allIdsWithFiltering = grid.jqGrid('getGridParam', 'lastSelectedData');

This returns a plain array, unlike the original answer, which returns an object with properties that must be enumerated.

这将返回一个普通数组,与原始答案不同,原始答案返回一个对象,该对象具有必须枚举的属性。

#3


0  

There is another way of getting this data in older versions on jqgrid:

在jqgrid的旧版本中,还有另一种获取数据的方法:

gRowNum = grid.jqGrid('getGridParam','rowNum');

grid.setGridParam({rowNum: '9999'});
grid.trigger("reloadGrid");
myList = grid.jqGrid('getDataIDs');

grid.setGridParam({rowNum: gRowNum});
grid.trigger("reloadGrid");

#1


13  

It is possible only if you have local grid (datatype:'local' or having loadonce:true). In the case all data inclusive ids for all pages are already locally. In the case you can use _index parameter, which will be used typically together with another more known parameter data. With

只有当您拥有本地网格(datatype:'local'或拥有loadonce:true)时,才可能实现。在这种情况下,所有页面的所有数据包含id都是本地的。在这种情况下,可以使用_index参数,它通常与另一个更已知的参数数据一起使用。与

var idToDataIndex = $("#list").jqGrid('getGridParam','_index');

you will get the _index parameter. It is an object which has as the properties all ids of grid. So you can enumerate the ids with

您将获得_index参数。它是一个具有所有网格id属性的对象。所以你可以用

var id;
for (id in idToDataIndex) {
    if (idToDataIndex.hasOwnProperty(id)) {
        // id is the rowid.
        // to get the data you can use
        // mydata[idToDataIndex[id]] where
        // var mydata = $("#list").jqGrid('getGridParam','data');
    }
}

#2


0  

In later versions of jqGrid they came out with a function that suits this situation better as it will consider any toolbar filtering that may be in place. See Oleg's example here. Thus, if you have a jqGrid (loadonce:true and/or datatype:local) the following will return all row ids (displayed in current page and beyond) which match the current filtering.

在jqGrid的后续版本中,他们提出了一个更适合这种情况的函数,因为它将考虑可能存在的任何工具栏过滤。看到奥列格的例子。因此,如果您有一个jqGrid (loadonce:true和/或datatype:local),下面将返回与当前过滤匹配的所有行id(显示在当前页和其他地方)。

var allIdsWithFiltering = grid.jqGrid('getGridParam', 'lastSelectedData');

This returns a plain array, unlike the original answer, which returns an object with properties that must be enumerated.

这将返回一个普通数组,与原始答案不同,原始答案返回一个对象,该对象具有必须枚举的属性。

#3


0  

There is another way of getting this data in older versions on jqgrid:

在jqgrid的旧版本中,还有另一种获取数据的方法:

gRowNum = grid.jqGrid('getGridParam','rowNum');

grid.setGridParam({rowNum: '9999'});
grid.trigger("reloadGrid");
myList = grid.jqGrid('getDataIDs');

grid.setGridParam({rowNum: gRowNum});
grid.trigger("reloadGrid");

相关文章