如何获得并设置农业电网状态? [英] How do I get and set ag-grid state?

查看:108
本文介绍了如何获得并设置农业电网状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取并重新设置农业网格表格的状态?我的意思是,显示哪些列,以什么顺序显示,以什么排序和过滤等。

How can I obtain and re-set the state of an ag-grid table? I mean, which columns are being show, in what order, with what sorting and filtering, etc.

更新:getColumnState和setColumnState似乎接近我想要的状态,但是我无法弄清楚应该在其中保存和恢复状态的回调。我尝试在onGridReady上还原它,但是在加载实际行时,状态丢失了。

Update: getColumnState and setColumnState seem to be close to what I want, but I cannot figure out the callbacks in which I should save and restore the state. I tried restoring it in onGridReady but when the actual rows are loaded, I lose the state.

推荐答案

有一个非常具体的示例在其网站上提供您要执行的操作的详细信息: javascript-grid-column-definitions

There is a very specific example on their website providing details for what you are trying to do: javascript-grid-column-definitions

function saveState() {
    window.colState = gridOptions.columnApi.getColumnState();
    window.groupState = gridOptions.columnApi.getColumnGroupState();
    window.sortState = gridOptions.api.getSortModel();
    window.filterState = gridOptions.api.getFilterModel();
    console.log('column state saved');
}

并进行恢复:

function restoreState() {
    gridOptions.columnApi.setColumnState(window.colState);
    gridOptions.columnApi.setColumnGroupState(window.groupState);
    gridOptions.api.setSortModel(window.sortState);
    gridOptions.api.setFilterModel(window.filterState);
    console.log('column state restored');
}

这篇关于如何获得并设置农业电网状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆