2012-08-31 66 views
0

我有一个大的列表,我已经实现了过滤。我希望用户能够选择一些行,过滤列表,选择更多,更改过滤器,选择更多,并保留所有选择。slickgrid选择行而过滤器忘记以前的选择

我下面这个例子: http://mleibman.github.com/SlickGrid/examples/example4-model.html

按照下列步骤来看看我的问题:

  1. 点击0行的10列
  2. 按住Shift键单击。现在选择0到10行。
  3. 将滑块上移至约90%,因此只显示0-10行中的几个。 (对我来说,2,6和8仍然显示并仍然被选中)
  4. 按住Ctrl键并点击未选择的行(对于我来说,第29行)
  5. 将过滤器滑回到零。

现在看到了这个问题。对我而言,只有第2,6,8和29行被选中。我宁愿选择0到10和29。有没有一个选择来获得这种行为?如果没有,有人可以推荐一种可行的方法吗?

回答

2

此问题已在Github上解决。

  • 首先,添加一个变量来存储id。
    • var selectedIds = [];
  • 其次,modifiy syncGridSelection
    • DataView.syncGridSelection(网格,真实的,真实的,功能(syncIds){selectedIds = syncIds;});
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();  
} 

请注意,此代码不会保留未通过过滤器的选定行。

+0

这被固定一个月前:[修正#498 - 选择滤波时,不会总是保持](https://github.com/mleibman/SlickGrid/commit/5b13782a50315f60aa911c360ec28d8ac9f63a42)。 – idbehold

+0

不知道。我会考虑在我的项目中升级slickgrid。 –

+0

idbehold,如果您想将该链接发布为答案,我会将其标记为正确。如果不是的话,我会自我回答,以便这个问题至少有一个答案。 –