诀窍是:
- 保存一些指示为每个选定的行
- 当你建立这行
- 呼叫“setSelectedRows”后“setGridData阵列中的选择的过滤数据,记“
这是做它的代码。
// filter grid without harming selection
// grid: a SlickGrid Object
// filter: a function that receieves a "data row" and returns true if it meets the filter
function filterGrid(grid,filter) {
var oldline;
var olddata=grid.getData();
var oldselection=grid.getSelectedRows()
var newline=0;
var newdata=[];
var newselection=[];
for (oldline=0; oldline<olddata.length ; oldline++) {
if (filter(olddata[oldline]) {
newdata.push(olddata[oldline]);
if (oldselection.indexOf(oldline)>-1) { // note on condition: ECMA5 - in IE8 you will need to loop
newselection.push(newline);
newline++;
}
}
}
grid.setData(newdata);
grid.setSelectedRows(newselection);
grid.updateRowCount();
grid.render();
}
请注意,此代码不会保留未通过过滤器的选定行。
这被固定一个月前:[修正#498 - 选择滤波时,不会总是保持](https://github.com/mleibman/SlickGrid/commit/5b13782a50315f60aa911c360ec28d8ac9f63a42)。 – idbehold
不知道。我会考虑在我的项目中升级slickgrid。 –
idbehold,如果您想将该链接发布为答案,我会将其标记为正确。如果不是的话,我会自我回答,以便这个问题至少有一个答案。 –