Page 1 of 1

Grid component selection when grouped and detail form

PostPosted: Wed Jul 13, 2022 9:20 am
by swingman
Hi, I'm on 2021.09 Ng client.

I have a list of people showing in a grid-component, the foundSet has multi-select on.
Next to it I have a detail form showing if only one record is selected, if more than record selected I show a form for merging records.

Everything works fine until I try to group the grid, let's say by company or status, expand the group and try to select individual people.
Then the detail form no longer updates to show the correct record.
I tried attaching a method to the onSelectedRowsChanged handler of the grid, but I can't seem to get this to work.

Any ideas how to implement this?

Re: Grid component selection when grouped and detail form

PostPosted: Wed Jul 13, 2022 9:47 am
by Gabi Boros
I guess onSelectedRowsChanged is triggered, right? Then to get the selected rows in grouping mode, you should use the getGroupedSelection api.

Re: Grid component selection when grouped and detail form

PostPosted: Wed Jul 13, 2022 9:53 am
by swingman
Code: Select all
elements.groupingtable_1.myFoundset.foundset.getSelectedRecords()


Gives me the selection before I grouped the grid, not what I have got selected now...
Is this a known bug, or am I doing something the wrong way?

Re: Grid component selection when grouped and detail form

PostPosted: Wed Jul 13, 2022 9:57 am
by swingman
Gabi Boros wrote:I guess onSelectedRowsChanged is triggered, right? Then to get the selected rows in grouping mode, you should use the getGroupedSelection api.


Ah, I has missed the API on the component itself, I had only looked at the foundSet.

Thanks Gabi, hopefully this was the missing piece.

Re: Grid component selection when grouped and detail form

PostPosted: Wed Jul 13, 2022 9:59 am
by Gabi Boros
in grouping mode you need to use getGroupedSelection to get the selected rows, because what you see in grouping mode is not the foundset anymore, but some internal foundsets created for grouping

Re: Grid component selection when grouped and detail form

PostPosted: Thu Oct 06, 2022 4:26 pm
by swingman
is there any way to set the selection when the grid is grouped?

Scenario:

The user works on multiple long lists and gets interrupted, jumping between the lists.

For every record select in the lists I record the state of each list, allowing the user to jump between lists but to maintain the position in each list.
I can restore list perfectly and the selection in the foundSet of a detail form, but cannot do the same for the data-grid.

So I end up with the correct list showing, the correct detail record showing, but no record selected in the data-grid...

My other option is to force-ungroup the grid somehow, because when the grid is ungrouped my logic works perfectly...
Is there a way to remove the grouping of data-grid programatically?

Re: Grid component selection when grouped and detail form

PostPosted: Thu Oct 06, 2022 5:13 pm
by swingman
OK, I have managed to ungroup:
Code: Select all
var state = elements.data_grid.getColumnState();

//remove grouping
var new_state = JSON.parse(state);
new_state["rowGroupColumnsState"] = "[]";
for (var e = 0; e < new_state["columnState"].length; e++) {
   new_state["columnState"][e]["rowGroupIndex"] = null;
}
//reapply columnstate without grouping
if (JSON.stringify(new_state) != state) elements.data_grid.restoreColumnState(JSON.stringify(new_state));