admin管理员组文章数量:1424887
I am using ag-grid:
tutorial.js:
(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:
<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>
So, whenever the "Refresh" button is clicked, all the sorting that is done on a column is refreshed and reset. Is it possible that the sorting doesn't reset whenever the refresh button is clicked but only the data is updated and the filter remains?
I am using ag-grid:
tutorial.js:
(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:
<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>
So, whenever the "Refresh" button is clicked, all the sorting that is done on a column is refreshed and reset. Is it possible that the sorting doesn't reset whenever the refresh button is clicked but only the data is updated and the filter remains?
Share Improve this question asked Sep 23, 2016 at 21:20 shekshek 2972 gold badges8 silver badges15 bronze badges2 Answers
Reset to default 3you need to add these filterParams
in your column defs:
{
headerName: 'athlete',
field: 'athlete',
editable: true,
width: 100,
filterParams: {apply: true, newRowsAction: 'keep'}
},
I asked the AG-Grid team the same question, check out the delta-row-data mode.
本文标签: javascriptHow to not reset filters after refresh button is clicked aggridStack Overflow
版权声明:本文标题:javascript - How to not reset filters after refresh button is clicked ag-grid - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745406481a2657273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论