JQGrid get all value for a particular column irres

2019-04-12 02:00发布

问题:

I am using "json" to pull data from db. How can I get all value for a particular column.

I want to get all value/full set of value for "PrimarySkill" column irrespective of paging.

var texts = $("#listTableSupply").jqGrid('getCol', 'PrimarySkill');

This code only giving me a subset of "PrimarySkill" i.e. giving me the value those are in current page.

I want full set value.

回答1:

If you have pure server side grid (with datatype: "xml" or datatype: "json" and you don't use loadonce: true) then jqGrid have no information about the data of other pages as the current page.

If you use local grid or remote grid where the server returns all data at once (loadonce: true are used) then the data are saved in internal _index and data parameters of jqGrid. So you can get the data using

var mydata = $("#listTableSupply").jqGrid("getGridParam", "data"),
    myPrimarySkill = $.map(mydata, function (item) { return item.PrimarySkill; });

alert (JSON.stringify(myPrimarySkill));

If you need to have the data in the format {id:rowid, value:cellvalue} (like getCol with true as the second parameter) then the code could be like the following

var mydata = $grid.jqGrid("getGridParam", "data"),
    ids = $grid.jqGrid("getGridParam", "_index"),
    myPrimarySkillWithIds = $.map(ids, function (index, key) {
        return { id: key, value: mydata[index].PrimarySkill };
    });

alert (JSON.stringify(myPrimarySkillWithIds));


标签: jquery jqgrid