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

select all rows in sub-grid when selecting a row on grid

Open kiransmk opened this issue 11 years ago • 13 comments

I need some help figuring out the how to programmatically select sub-grid rows if I select the row check box. Here is my code http://plnkr.co/edit/oB6AK7uf2TpIJ1V4yi9y?p=preview Also the selected rows state is not saved when I collapse the row.

kiransmk avatar May 26 '15 23:05 kiransmk

I've already done that. Choosing all of the subGrid elements is quite easy. The problem with your example is, that the subGrid data is always being taken from the server when the subGrid reopens, so it can't save the status. Here's an example of selecting subGrid rows if selecting the row check box: http://plnkr.co/edit/Q7B5GKT51sHjgJGth5pJ?p=preview Look at the TODO in the subGridRegister function - it's pretty easy to do, but something needs to be left for you to do, right? Hope this helps...

YonatanKra avatar May 27 '15 12:05 YonatanKra

Thanks yccteam. I have tried to use the other approach. http://plnkr.co/edit/DfYtLmZrzOMl411AwBrg?p=preview It still doesn't save the state when collapsed and expanded again.

kiransmk avatar May 27 '15 18:05 kiransmk

I could not see any change you did, but please check this one: http://plnkr.co/edit/R0kin0RRTbyq05aRUilT?p=preview

YonatanKra avatar May 27 '15 19:05 YonatanKra

Hi yccteam thanks. But I still don't see the check-box states in subgrid being saved when you collapse and expand. Change I made is the subgrid data, it is not doing http server request when row is expanded to display subgrid. http://plnkr.co/edit/DauNfut8l2GTGdbLBipb?p=preview I am trying to see if I can set it in the rowExpandedStateChanged. I am new to Angular and ui-grid. So, I am still figuring out the flow of data.

kiransmk avatar May 27 '15 20:05 kiransmk

Hi @kiransmk, In this example: http://plnkr.co/edit/R0kin0RRTbyq05aRUilT?p=preview

  1. Expand a row
  2. Make your selections
  3. Collapse the row
  4. Expand the row again
  5. Note that selection was saved.
  6. Now select the parent row
  7. Note that all the rows in the subGrid are selected
  8. Unselect the parent row
  9. Note that all the rows in the subGrid are unselected From what I understand, fullfils your requirments from above. The code and logic can be different a little bit according to your scenario, but in this scenario my code did the trick. Let me know if I missed something.

YonatanKra avatar May 28 '15 08:05 YonatanKra

Thanks yccteam. Now I see the state is saved when you check the subgrid rows. This is great. But still when I

  1. Expand a row and select the row to select all rows in subgrid,
  2. collapse
  3. expand,
  4. note the selection is not saved in the subgrid.

kiransmk avatar May 28 '15 17:05 kiransmk

The subgrid ceases to exist when the row is collapsed. This is the behavior of the expandable-row feature. It uses ng-if to show/hide the expanded content.

This means that any state that was saved is lost because the element was lost. State would somehow need to be saved in the application itself, outside of the grid.

c0bra avatar Jun 02 '15 15:06 c0bra

Sorry for missing your response @kiransmk. Actually, @c0bra 's answer is the reason why in the example above (http://plnkr.co/edit/R0kin0RRTbyq05aRUilT?p=preview) I save the selection status in the parent row and it remembers the selection also after collapsing and expanding. @kiransmk - please verify it works on your end. It works on my end.

  1. Expand a row and select the row to select all rows in subgrid,
  2. collapse
  3. expand,
  4. note the selection is saved in the subgrid.

YonatanKra avatar Jun 02 '15 15:06 YonatanKra

Thanks @c0bra, that makes sense now. @yccteam the complete subgrid selection state is not saved. I will try to dig in deeper in the code and see if I can figure it what I want. I will post it on here when I find a solution.

kiransmk avatar Jun 03 '15 00:06 kiransmk

I couldn't get it to work. But, the grouping seems to work for with some modifications. I have one question in grouping too. If you guys can help it would be great. I am performing aggregate on the selected rows, but aggregate is not updated simultaneously on selection of a row. All I want to display is when user selects a row it should update the number of rows selected in sub-group. Here is my code. http://plnkr.co/edit/a7dc4TwiVT7mXCsuxRx1?p=preview

kiransmk avatar Jun 16 '15 01:06 kiransmk

Effectively what you're doing is updating the data in the array, and the grid doesn't notice that unless you tell it. Because what you're doing is updating the data, then you want the grid to run the rowsProcessors again to aggregate the data, the easiest way to do this is queueGridRefresh().

http://plnkr.co/edit/H1B3rKrMM4RaUH5SPVaF?p=preview

PaulL1 avatar Jun 19 '15 19:06 PaulL1

Awesome thanks, this works for me. You can close this issue.

kiransmk avatar Jun 22 '15 17:06 kiransmk

Hi c0bra

Can you help me, in UI Grid,
http://plnkr.co/edit/R0kin0RRTbyq05aRUilT?p=preview, selected rows are not when

  1. Expand grid, 2 Select rows(parent and child)
  2. collapse 4.Now Expand, selections are disappearing, state is not maintaining , can you help me ,

Thanks..!!

Dattugadu avatar Feb 27 '18 20:02 Dattugadu