mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

Group selection with Checkbox #1149

Open manish2612 opened 7 years ago

manish2612 commented 7 years ago

User should be able to selected entire group with checkbox in group header row. Every time I need to check each ro checkbox separately to select row. If I have more than 5-6 records it's not convenient.

chaitanya121 commented 7 years ago

Hi Manish

Any luck...I also need to implement same functionality..

6pac commented 7 years ago

http://6pac.github.io/SlickGrid/examples/example-grouping-checkbox-row-select.html

in the 6pac repo

harit2101 commented 7 years ago

Hi,

My requirement is like a tree with expand, collapse and checkbox functionality. Done with display of tree with expand and collapse functionality . Need help in implementation of checbox functionality so that it covers below scenarios

1) parent node selected then all child nodes must be selected. 2)parent node unchecked then all child nodes must be unchecked. 3) if parent has 3 child node, out of which 1 child node is checked and 2 are unchecked then parent node must be in intermediate state of checkbox. Like half selected. 4) if user manually unchecked all child node then parent node must be unchecked.

Below is tree structure

- rootNode
  --child1
  --child2
     ---childOFChild2

Followed below link for tree implementation. https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example5-collapsing.html

Any help would be GREAT..

manish2612 commented 7 years ago

Hi Chaitanya, I have implemented this functionality with few changes in checkbox plugin. There are 2 properties associated with row which is differentiating between group checkbox and child checkbox.OnChange event of header checkbox I am caching all the child checkboxes and updating thier states as well as selectedRows for grid.

cvium commented 6 years ago

Hi @Manish2612

Do you have some example code?

6pac commented 6 years ago

@Manish2612 would you like to raise a pull request against the 6pac repo. I've got a basic example (comment above) of the tree parent selection, but it just does selection or deselection of the group rows if the user checks or clears the group header checkbox. No intermediate state tracking.

cvium commented 6 years ago

@6pac I have noticed some odd behaviour in your example. When some rows are selected/checked and you collapse the group, the rows are still marked as selected. Example: https://imgur.com/a/VJxv9

6pac commented 6 years ago

@cvium it's like I always say, SlickGrid is a toolkit to be adapted to your use case, not a finished product. There are always many different opinions on what the 'correct' behaviour should be. To me, what you have described is exactly how I would expect the grid to operate. Why would collapsing a group remove the checks? Clearly you have different expectations :-)

cvium commented 6 years ago

I think most users would expect the same as me. It's even the default behaviour in Excel.

6pac commented 6 years ago

Yes, I know. Everyone even always says 'I think most users would expect the same as me' :-)

Personally, I don't see this as a particularly good Excel grid, nor Excel behaviour as its prime function. The functions are there, but I suspect other grids do them better. I see groups and collapsing as a way of conveniently navigating through a large dataset. If the selections disappeared on collapsing, I'd be quite annoyed, if I was trying to put together a number of selections.

But I'm saying there will always be debate over incompatible and perfectly valid use cases. Neither you or I are right - or to put it another way, we are both right. It's bewildering for me to try to cater for all possible use cases, and all the options tend to obscure the base code and make it harder to work with. This is why I view SlickGrid primarily as a toolkit.

On the other hand, if you can somehow make this available as an option elegantly, and maybe offer some useful additional functionality (the selection/collapsing examples are still quite primitive at the moment), create an example to showcase it, and offer it as a pull request, I'm all ears!

cvium commented 6 years ago

I'm not saying the selection should disappear, it should just be hidden along with the rows ie. selection should be tied to the specific data rows instead of the grid rows (if that makes sense). This obviously requires some state management of sorts.

We have a data set with roughly 800 rows spread across 40 categories/groups. For reasons I don't fully agree with, we cannot use paging, so I'm debating our options -- it's currently between SlickGrid and jQuery DataTables. For our use case, the selection should be tied to the data and not the grid itself. If it is too time consuming to make it do this, then we'll probably use jQuery DataTables with some grouping hacks (its RowGroup extension is incredibly naive and performance suffers for it). So at its core we just need a table that supports grouping, sorting, filtering and virtual scrolling. SlickGrid is obviously much more than that, but out of the tools I've tried, it's been the most pleasant to work with.

Anway, I digress... If I can make this work and it's not too specific to our use case, I will gladly open a PR, but we don't have OSS contributions as part of our budget, so the PR would be on my own (limited) time.

6pac commented 6 years ago

Ah, my apologies, I didn't look closely enough at the images. Yes, that is a bug. Are you using SyncGridSelection()? https://github.com/mleibman/SlickGrid/wiki/DataView

It's too late here. I'll look tomorrow.

cvium commented 6 years ago

That I am not. I just used this example: http://6pac.github.io/SlickGrid/examples/example-grouping-checkbox-row-select.html, which doesn't seem to use it.

I'll see if SyncGridSelection() does it... tomorrow at work. Thanks.

cvium commented 6 years ago

@6pac SyncGridSelection() did the trick, but if a selection is collapsed and you select some other rows, it will "forget" the collapsed selection. Multi-select is enabled, so it's just an issue with selection state on collapsed groups. Is this intended or am I missing another piece of the puzzle?

6pac commented 6 years ago

Looks like I need to check this out. I'll use the example page as the test case. It would be good if you could feed your changes through. You are using my repo as a baseline? This repo is extremely out of date and no longer maintained.

cvium commented 6 years ago

@6pac Yes. I simply noticed some activity in this issue and jumped on it. As for the current problem, I have narrowed it down a bit. The selectedRowIds array is overwritten with the visible selections whenever grid.onSelectedRowsChanged is triggered.