ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Selecting rows in sub-grids (state is not maintained on expand/collapse)

Open tojojose opened this issue 11 years ago • 17 comments

Hi , Could some one help me with the Expandable UI Grid , ( UI Grid with In UI Grid) , code in plnkr - http://plnkr.co/Eeg5YiIvFa5TpD8PLb3i . I was trying to find out the code , that can be used to capture child grid (sub grid) raw selection , any help on this topic will be welcome.

thanks

tojojose avatar Mar 23 '15 19:03 tojojose

Can you explain exactly what you mean by "sub grid raw selection"? It sounds like you're wanting to select rows in sub-grids but I can't be sure.

c0bra avatar Mar 24 '15 17:03 c0bra

Yes , i want to allow the user to select a row in the sub grid and need to capture the event in the controller , set the selected raw values to a $scope variable.

thanks

tojojose avatar Mar 24 '15 17:03 tojojose

Could you please acknowledge my response , i just wanted to make sure , i have conveyed it correctly.

tojojose avatar Mar 26 '15 16:03 tojojose

@tojojose Yea sorry I understand what you're trying to do.

Unfortunately right now it looks like subgrids don't maintain row selection state on expand/collapse so your use case will be a bit broken.

The way you'd want to go about it is to register a gridApi.selection.on event handler for all your subgrid options and push/splice the selected/deselected rows into a single array in your parent scope.

Problem is that it will be broken until the subgrid state issue is fixed. I'll mark this as a bug.

@jpuri do you have any ideas on maintaining state in subgrids like this?

c0bra avatar Mar 30 '15 15:03 c0bra

@c0bra currently to maintain selection state we can make use of event "rowExpandedStateChanged" to save the selected rows when subgrid is closed.

But yes we can take up this as enhancement of maintaining subgrid state across expand / collapse.

@tojojose, for details of subgrid scope check "expandableRowScope" in tutorials, let me know if you need more details.

jpuri avatar Mar 30 '15 16:03 jpuri

Hi @c0bra , @PaulL1 ,

Any thoughts on how can we implement subgrid state. I think its right now broken because of some issues with how scope works for grid. Subgrid exists in scope of enclosing row.

jpuri avatar Apr 06 '15 14:04 jpuri

@jpuri yes I think we'd have to update state-saving a bit and register a different location (i.e. the GridRow object) to store the state in.

c0bra avatar Apr 06 '15 22:04 c0bra

There is actually some complexity to it:

  1. Subgrid can be anything a grid or whatever else user provides in the template.
  2. When an expandable grid is rendered and expanded subgrid is appended to each row although its hidden. When user choses to expand the row this subgrid is shown. If we show hide a top level grid its state is maintained but this is not the case with subgrid.
  3. A subgrid is a complete grid in its own and does not have idea of its parent grid. Its state exists independently. Thus a grid never know if its sub-grid and should save some state or reload some state.

jpuri avatar Apr 08 '15 10:04 jpuri

If you were OK with a dependency on saveState, you could call saveState on collapse, and save it on the parent row (perhaps as row.subgridState), then call restoreState when you show it again.

Something about this feels a bit wrong to me though - it feels too complex and therefore perhaps too fragile. But maybe you just put in the saveState call and it just works.

PaulL1 avatar Apr 08 '15 19:04 PaulL1

Actually subgrid's scope is child of parent grid, I have no access to subgrid in supergrid. Thus its difficult for me to get sub-grid state (subgrid again can be any template not just ui-grid).

What looks more appropriate to that I add callback for user to be able to save and set subgrid state. But it might be difficult for even user to reset sub-grid state as he also will not have direct access to subgrid scope.

But I am sure there would be some way to achieve, let me think more about it.

jpuri avatar Apr 10 '15 13:04 jpuri

Hi @jpuri and @c0bra,

Any updates on this enhancement? I am currently dealing with this issue.

Thanks!

htrajan avatar Nov 10 '15 21:11 htrajan

Hi Guys,

I am having difficulty with sub-grid. I having sub-grid under main UI-grid and after expanding parent row, I'm selecting rows from sub-grid and then collapsing parent row. After I'm expanding parent raw again, my selected rows goes un-selected. I am using gridApi.expandable.on.rowExpandedStateChanged event. attached is my code for the same.

Kindly advice me soon, as it's kind of urgent. UI-Sub_grid.txt

girish-fuluskar avatar Mar 13 '17 11:03 girish-fuluskar

I have managed to fixed this...

girish-fuluskar avatar Mar 14 '17 07:03 girish-fuluskar

@girish-fuluskar You can reset the link to your source? solution to the problem. thanks)

ghost avatar Mar 24 '17 15:03 ghost

@girish-fuluskar Could you please share how this has been solved?

BPoorey avatar Apr 26 '17 09:04 BPoorey

Use the timeout function. Implemented, maybe not beautiful, but WORKS.

Then refused to use ui-grid, due to the absence of the third state.

Look, who can help with the developments.

Happened. File attached: MyCtrl.txt

ghost avatar Aug 16 '17 13:08 ghost

Hi @girish-fuluskar Can you help me, how you managed the subgrid selection, after collapse. I need it on priority . My code is similar kind of thing. http://plnkr.co/edit/R0kin0RRTbyq05aRUilT?p=preview

thanks.!!

Dattugadu avatar Feb 27 '18 20:02 Dattugadu