You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PQGrid中获取与JQGrid.getGridParam("postData").filters等效的筛选及排序信息以保存网格状态?

Getting Equivalent Filter & Sort State in PQGrid (Like jqGrid's postData.filters)

Great question! If you're used to grabbing filter and sort info from jqGrid with getGridParam("postData").filters, here's how you can do the exact same thing in PQGrid to save and restore grid state:

1. Grab Current Filter Conditions

PQGrid has a built-in getFilter() method that returns the full current filter configuration—this is the direct equivalent to jqGrid's filters object. It includes all column-specific filter rules, group operations (AND/OR), and any nested filter groups.

Example code:

// Assuming your grid instance is stored in a variable like `myGrid`
var currentFilters = myGrid.getFilter();

The returned currentFilters object will have a structure like this (simplified):

{
  "groupOp": "AND",
  "data": [
    { "dataIndx": "name", "condition": "contains", "value": "john" },
    { "dataIndx": "age", "condition": "gte", "value": "30" }
  ]
}

2. Get Current Sort Configuration

To capture the active sorting state, use the getSortModel() method. This returns an array of objects representing each sorted column (including sort direction).

Example code:

var currentSort = myGrid.getSortModel();

Sample output:

[
  { "dataIndx": "age", "sortDir": "desc" },
  { "dataIndx": "name", "sortDir": "asc" }
]

3. Combine & Save State

To save the full grid state (filters + sorting), just combine these two values into a single object and store it (e.g., in localStorage or send it to your backend):

// Combine filter and sort state
var gridState = {
  filters: currentFilters,
  sortModel: currentSort
};

// Save to localStorage
localStorage.setItem("pqGridState", JSON.stringify(gridState));

4. Restore Saved State

When you need to restore the state later, retrieve the saved object and use PQGrid's setter methods:

var savedState = JSON.parse(localStorage.getItem("pqGridState"));
if (savedState) {
  // Restore filters
  myGrid.setFilter(savedState.filters);
  // Restore sorting
  myGrid.setSortModel(savedState.sortModel);
  // Refresh the grid to apply changes
  myGrid.refresh();
}

Key Note

Unlike jqGrid's postData.filters, PQGrid's getFilter() returns a structure that's natively understood by the grid's setFilter() method—so you won't need extra parsing or conversion if you're just using it for state persistence. If you specifically need to match jqGrid's filter format, you can map the PQGrid filter object to jqGrid's structure manually, but that's usually unnecessary for state saving.

内容的提问来源于stack exchange,提问作者Aniruddha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 02:17:43