jQuery 如何使用分页获取jqgrid中所有行的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19703308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:27:57  来源:igfitidea点击:

How to get data for all rows in jqgrid with pagination

jqueryjqgrid

提问by mailmehere

I want to access grid data as below

我想访问网格数据如下

    var namePresent;
    var datafromgrid = $('#MyGrid').jqGrid('getRowData');
    for (var i = 0; i < rowCount; i++) {
         var name = datafromgrid[i].Name;
         var firstname = name.split(/ +/);
         if (firstname[0].toLowerCase() == Name.toLowerCase()) {
             namePresent = 1;
         }
    }

Now suppose when my grid is loaded with 5 records then this code throws error on line var name = griddata[i].Name;as from grid it is unable to read griddata[5]. Please tell me how to read whole grid data even if it is not visible on screen but is fetched successfully?

现在假设当我的网格加载了 5 条记录时,此代码会在行 var 上引发错误,name = griddata[i].Name;因为它无法读取网格数据 [5]。请告诉我如何读取整个网格数据,即使它在屏幕上不可见但已成功获取?

回答by checkgdata

you can try using :

你可以尝试使用:

var allRowsInGrid = $('#list4').jqGrid('getGridParam','data');

回答by Maverick

This way is more "pretty":

这种方式更“漂亮”:

var allRowsInGrid = $('#list4').getGridParam('data');

回答by Mzn

This is an alternative way to get the data of a particular row. You can loop over all rows to get everything:

这是获取特定行数据的另一种方法。您可以遍历所有行以获取所有内容:

var dataIDs = grid.getDataIDs(); 
for(i = 0; i < dataIDs.length; i++)
{
    var rowData = grid.jqGrid ('getRowData', dataIDs[i]);
    //rowData is object containing keys & values for row
    console.log(rowData);
}

回答by Dulith De Costa

After digging into the documentation, found this straight forward way.

在深入研究文档后,找到了这种直接的方法。

var allRowsInGrid = $('#list4').getGridParam('data');

This returns you a JavaScript Array Object. To check the values in JS Object you can simply use following way.

这将返回一个 JavaScript 数组对象。要检查 JS 对象中的值,您可以简单地使用以下方式。

var stringVersion = JSON.stringify(allRowsInGrid);

alert (stringVersion);