首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在单击刷新按钮后不重置筛选器

如何在单击刷新按钮后不重置筛选器
EN

Stack Overflow用户
提问于 2016-09-24 05:20:22
回答 2查看 2.9K关注 0票数 3

我使用的是ag-grid:

tutorial.js:

代码语言:javascript
复制
(function() {
var columnDefs = [
    {headerName: "Athlete", field: "athlete", width: 150, filter: 'set'},
    {headerName: "Age", field: "age", width: 90, cellRendered: timestampCellRenderer}

];

function timestampCellRenderer(params) {
    return params.value + ' <span style="font-size: 10px; color: grey;">' + new Date().getTime() + '</span>';
}


function onRefreshAll() {
    gridOptions.api.refreshView();
}
var gridOptions = {
    columnDefs: columnDefs,
    rowData: null,
    enableSorting: true,
    enableFilter: true,
    enableColResize: true
};


// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
    var gridDiv = document.querySelector('#myGrid1');
    new agGrid.Grid(gridDiv, gridOptions);

    // do http request to get our sample data - not using any framework to keep the example self contained.
    // you will probably use a framework like JQuery, Angular or something else to do your HTTP calls.
    var httpRequest = new XMLHttpRequest();
    httpRequest.open('GET', '../dist/olympicWinners.json');
    httpRequest.send();
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            var httpResult = JSON.parse(httpRequest.responseText);
            gridOptions.api.setRowData(httpResult);
            gridOptions.api.sizeColumnsToFit();
            console.log(httpResult);
        }
    };
});
window.onRefreshAll = onRefreshAll;
})()

index.html:

代码语言:javascript
复制
<html>
<head>
    <!-- you don't need ignore=notused in your code, this is just here to trick the cache -->
    <script src="../dist/ag-grid-enterprise.js?ignore=notused31"></script>
    <script src="tutorial1.js"></script>
    <script src="tutorial.js"></script>

</head>
<body>
<div id="myGrid1" class="ag-fresh" style="height: 400px;"></div>
<div>
    <span style="padding-bottom: 4px; display: inline-block;">
        <button onclick="onRefreshAll()">Ireland & UK</button>


    </span>
    <br/>

</div>

<div id="myGrid" class="ag-fresh" style="height: 400px;"></div>

</body>
</html>

因此,每当单击“刷新”按钮时,对列所做的所有排序都会被刷新并重置。有没有可能,每当单击刷新按钮时,排序都不会重置,而只是更新数据并保留筛选器?

EN

回答 2

Stack Overflow用户

发布于 2018-12-04 23:49:25

您需要在您的defs列中添加以下filterParams

代码语言:javascript
复制
  {
    headerName: 'athlete',
    field: 'athlete',
    editable: true,
    width: 100,
    filterParams: {apply: true, newRowsAction: 'keep'}
  },
票数 2
EN

Stack Overflow用户

发布于 2017-06-16 00:01:02

我问了AG-Grid团队同样的问题,看看delta-row-data模式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39669719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档