slickgrid选择行同时过滤器是忘记先前的选择(slickgrid select rows wh

2019-09-22 00:39发布

I have a large list where I've implemented filtering. I'd like to user to be able to select some rows, filter the list, select a few more, change the filter, select more, and have all of the selections remain.

I am following this example: http://mleibman.github.com/SlickGrid/examples/example4-model.html

Follow these steps to see my problem:

  1. Click on the 0 row
  2. Shift-click on the 10 row. Rows 0 through 10 are selected now.
  3. Move the slider up to about 90%, so only a few of the rows 0 - 10 show. (For me, 2, 6, and 8 still show and are still selected.)
  4. Ctrl-click on an un-selected row (for me, row 29)
  5. Slide the filter back down to zero.

Now this issue is seen. For me, only rows 2, 6, 8, and 29 are selected. I would prefer that 0 through 10 and 29 remain selected. Is there an option to get this behavior? If not, can someone recommend an approach that might work?

Answer 1:

此问题已得到解决在Github上 。

  • 首先,添加一个变量来存储ID。
    • VAR selectedIds = [];
  • 其次,modifiy syncGridSelection
    • DataView.syncGridSelection(网格,真实的,真实的,功能(syncIds){selectedIds = syncIds;});


Answer 2:

诀窍是:

  1. 保存一些指示为每个选定的行
  2. 在构建经滤波的数据,请注意哪些线阵列中的被选择
  3. 呼叫“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();      
}

请注意,这个代码不保留不通过过滤器选择的行。



文章来源: slickgrid select rows while filter is on forgets previous selections
标签: slickgrid