10

current grid status

I've implemented a slick grid with a custom selection model as well as a custom checkbox selection plugin. I've also added group level checkboxes to allow toggling selection at the top level. One of my requirements is that collapsed groupings are still selectable via any parent level grouping checkboxes.

My stumbling block seems to be that I can't figure out how to select rows that aren't currently visible on the group. The slick grid maintains the set of visually selected items while the grids data view maintains the full set of selected items, visible or not. However, I can't figure out how to pipe into data when clicking the group checkbox of a collapsed row.

I am configuring my grid like so:

let checkboxSelectionModel = new Slick.CheckboxSelectionModel();
this.grid.setSelectionModel(checkboxSelectionModel);

this.grid.registerPlugin(new Slick.Data.GroupItemMetadataProvider());

let onSelectedRowIdsChanged = this.dataProvider.syncGridSelection(this.grid, true, true);

onSelectedRowIdsChanged.subscribe(
  function(e: any, args: any)
    {
      //business logic stuff                    
    }
  );

let groupedCheckboxSelector = new Slick.GroupedCheckboxSelectColumn({
  cssClass: "slick-cell-checkboxsel",
  onSelectedRowIdsChangedHandler: onSelectedRowIdsChanged
});

let columns = this.grid.getColumns();
columns.unshift(groupedCheckboxSelector.getColumnDefinition());
this.grid.setColumns(columns);

this.grid.registerPlugin(groupedCheckboxSelector);

gist to custom plugins, too long to include here Specifically, if you look at line 57 of slick.checkboxselectionmodel:

$.each(dataItem.rows, function(index, groupRow) {
  var groupRowIndex = _self._grid.getData().getRowById(groupRow.id);
    if (groupRowIndex) {
      selection.push(groupRowIndex);
    }
});

groupRowIndex is never resolved for hidden rows, and so never get selected. I attempted to expand the group when clicked, then resolve the rows, which works but when the group is collapsed afterward, the wrong rows are selected in the grid.

any help would be greatly appreciated!

some notes:

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
Julien
  • 212
  • 1
  • 18
  • 53
  • 2
    i will put up a fat bounty as soon as possible – Julien Feb 04 '20 at 16:09
  • 1
    There's an opened [issue #165](https://github.com/6pac/SlickGrid/issues/165) for this, and I think what would help is that you or anyone else just provide a fix to that issue in the 6pac fork. This is an Open Source project with contributions from the community, so any contributions help to make this lib better over the years. – ghiscoding Feb 06 '20 at 17:12

1 Answers1

1

gist to updated plugins

A functional solution that I'm confident could put anyone seeking similar behavior on the right path, however, I'm not sure how well either of these plugins would work independently. one of my requirements was to only allow row selection via the row checkbox.

one gotcha (that I'm sure is easily improved) is that the group level checkbox still needs to be defined in your group format operator

the main solution to my issue was to expand all collapsed groups when making group-level selects/unselects, perform any select/unselect routines, then collapse any previously expanded groups

EDIT:

This fails when the grid has large amounts of data (10k rows). Re-opening with a bounty.

It looks like the performance hit of having to expand and collapse so many groups cause issues.

Community
  • 1
  • 1
Julien
  • 212
  • 1
  • 18
  • 53
  • 1
    @AmerllicA this answer was premature and does not work with large datasets – Julien Feb 20 '20 at 13:56
  • 1
    @AmerllicA it's not only unethical to please like this for some bounty, but actually the OP started the bounty after this answer was posted and that's because the OP didn't have the results he wanted with this answer. So, please stop begging like this for bounty that you haven't earned and instead try and help OP with his problem if you have time to come up with a good/better solution. – Christos Lytras Feb 21 '20 at 13:39
  • @ChristosLytras, I will delete my comment immediately, thanks for the hint. – AmerllicA Feb 21 '20 at 13:44
  • @ChristosLytras thought the same thing, couldn't have said it better – Alexandre Elshobokshy Feb 21 '20 at 15:51