简体   繁体   English

如何导出所有应该只有可见列的jqgrid数据,而不管分页

[英]how to export all jqgrid data which should have only visible columns irrespective of paging

I want to know whether there is any method to get all jqGrid data of visible columns irrespective of paging. 我想知道是否有任何方法来获取可见列的所有jqGrid数据而不管分页。

$("#listTableSupply").jqGrid("getGridParam", "data");

But it shows all json data which I have passed to jqgrid. 但它显示了我传递给jqgrid的所有json数据。 As I use paging in jqgrid if I use 因为我在jqgrid中使用分页,如果我使用

$('#list').jqGrid('getRowData');

I get only the records from 1st Page. 我只得到第一页的记录。

I need to know is there any way that I have to get all data with visible columns irrespective of paging. 我需要知道是否有任何方法我必须使用可见列获取所有数据,而不管分页。

The usage of getGridParam with data is the correct way. getGridParamdata的使用是正确的方法。 If you need to remove some properties from the item or the array then you should make deep copy of the array (by usage of $.extend(true, {}, data) ) and remove unneeded properties from every item of the array. 如果需要从项目或数组中删除某些属性,则应该对数组进行深层复制(通过使用$.extend(true, {}, data) )并从数组的每个项目中删除不需要的属性。

Alternatively you can copy all properties with non-hidden columns in new array. 或者,您可以在新数组中复制具有非隐藏列的所有属性。 The code could be about the following: 代码可以是以下内容:

// get the reference to all parameters of the grid
var p = $("#listTableSupply").jqGrid("getGridParam");

// save the list of all non-hidden columns as properties of helper object
var colNames = {}, i, cm;
for (i = 0; i < p.colModel.length; i++) {
    cm = p.colModel[i];
    if (cm.hidden !== true) {
        colNames[cm.name] = true;
    }
}
// We have now colNames object with properties,
// which correspond to non-hidden columns of the grid

// Make copy of p.data including only non-hidden columns
var newData = new Array(p.data.length), prop, newItem, item;
for (i = 0; i < p.data.length; i++) {
    item = p.data[i];
    newItem = {};
    for (prop in item) {
        if (item.hasOwnProperty(prop) && colNames[prop]) {
            // fill only properties of non-hidden columns
            newItem[prop] = item[prop];
        }
    }
    newData[i] = newItem;
}

I don't tested the above code, but I hope it fill newData array with the data, which you need. 我没有测试上面的代码,但我希望它用你需要的数据填充newData数组。

UPDATED: I created the demo for you, which demonstrates the usage of lastSelectedData instead of data . 更新:我为您创建了演示 ,演示了lastSelectedData而不是data的用法。 It fills in the resulting array newData the filtered items of the grid, including only visible columns. 它在结果数组newData填充newData的过滤项,仅包括可见列。 You can filter the data and then click on the button "Show non-hidden fields of filtered and sorted data". 您可以过滤数据,然后单击“显示已过滤和排序数据的非隐藏字段”按钮。 The demo fills the newData array and display it. 该演示填充newData数组并显示它。 I used the following code inside of click handler: 我在click处理程序中使用了以下代码:

var p = $grid.jqGrid("getGridParam"), filteredData = p.lastSelectedData,
    idName = p.localReader.id, i, cm, prop, newItem, item,
    colNames = {}, newData;
if (p.lastSelectedData.length > 0) {
    for (i = 0; i < p.colModel.length; i++) {
        cm = p.colModel[i];
        if (cm.hidden !== true && $.inArray(cm.name, ["rn", "cb", "subgrid"]) < 0) {
            colNames[cm.name] = true;
        }
    }
    colNames[idName] = true;
    newData = new Array(p.lastSelectedData.length);
    for (i = 0; i < p.lastSelectedData.length; i++) {
        item = p.lastSelectedData[i];
        newItem = {};
        for (prop in item) {
            if (item.hasOwnProperty(prop) && colNames[prop]) {
                // fill only properties of non-hidden columns
                newItem[prop] = item[prop];
            }
        }
        newData[i] = newItem;
    }
    alert(JSON.stringify(newData));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM