-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GridStateService always clear row selections even though syncGridSelection is TRUE #295
Comments
The row selection is not, and will not, be part of the Grid State & Presets feature simply because there is no guarantee that the data will always be the same and the row selection is by row index and has no connection with the data itself. The Grid State/Presets is only meant for Grid Filtering, Sorting & Column Position, nothing else. I do not want to change that. Basically if you want to keep the row selection, you'll have to do it manually, which is not that hard to do with |
Actually I'm just trying to make use of the readily available feature in 6pac/SlickGrid as described in https://github.com/6pac/SlickGrid/wiki/DataView#synchronizing-selection--cell-css-styles Thanks for the feedback. Will explore further |
For any features or special code that is not directly available in Angular-Slickgrid, you can use the SlickGrid Grid Object and DataView Object as shown in this Wiki. These objects were exposed for that reason. The main difference with the core lib, is that I use only the DataView in my lib (so manipulating the data as to be with the DataView), so that is something to keep in mind. The one place I play with CSS styling is for highlighting a row, with this method, I use the row metadata as described in this SO. Kind of complicate with metadata just to highlight a row, but it works. |
I'm experiencing the same problem, and I don't understand how the suggested solution of handling |
I'm going to repeat again that it's by design, I never intended to add the Row Selection in the Grid State, it doesn't belong there and I won't add it. The reason is the same as I mentioned earlier
|
@timhawkins1 Instead of using the built-in checkbox, I solved my problem using a checkbox column & process the onCellClick event & save the selection state into the row item. No more idiosyncrasy due to sorting/filtering |
@whtan98 Thanks for the help. I have it working now in the way that you described. The only thing I couldn't work out how to implement was a header checkbox, so instead I've added a Check/Uncheck All button to my page, which I think is good enough. |
@timhawkins1 You're welcome, I believe you can refer to example |
I'm reopening this issue as I recently came across the
I would like some feedback on the Grid State & Presets, I'm adding a new property export interface CurrentRowSelection {
/** Grid Row Indexes, based on the row position in the grid (what we see in the UI) */
gridRowIndexes?: number[];
/** Row Selection by the Row Data Context, in other words we select the row by the data object ID */
dataContextIds?: number[];
} DemoThe print screen below shows a Grid Presets with an IDs of Tasks with IDs=2 & 6 (the ID is equal to the Task number), these tasks are on the first 2 pages of this grid and the presets: {
pagination: { pageNumber: 2, pageSize: 5 },
// row selection, use only the best array for your use case and remove the other one
// it will always start with the "dataContextIds" array, if nothing is found it will go to "gridRowIndexes"
rowSelection: { dataContextIds: [2, 6], /*gridRowIndexes: [2],*/ }
}, Note on Backend ServicesI don't think this would necessarily or always work with |
Hmm I do see a big problem when using Local Grid Pagination, when calling So basically this Grid State would work properly on a grid without any Pagination, but it's a big issue when using Local Grid Pagination, as shown in Example 10, and now I'm starting to question if I should continue with this and/or maybe disable the Grid State Possible solution, I see this SO which is the same as my problem, but that requires more work... after some thought that probably won't work correctly either since there's no way to know if the click was to add or remove a selection. |
- closes #295 - with the "syncGridSelection" enabled in the DataView we can now add the Row Selection to the Grid State & Presets (for that the flags "enableCheckboxSelector" or "enableRowSelection" must be enabled)
…ets (#388) * feat(selection): preserve row selection & add it to Grid State & Presets - closes #295 - with the "syncGridSelection" enabled in the DataView we can now add the Row Selection to the Grid State & Presets (for that the flags "enableCheckboxSelector" or "enableRowSelection" must be enabled) * (odata): fix TS typing warning in a Jest unit test
This was more complicated than I imagined (because of possible Local Grid Pagination) but I managed to get it all done. We now have a new Grid State property This is now in place and will be released soon. |
I appreciate the effort you've put into this, but I still can't get it to work. I've updated to the latest release of Angular-Slickgrid, but the row selections are still lost whenever I filter or sort the grid. I'm not sure what I need to do to retain them. Can you provide an example that demonstrates this functionality working? Both grids in Example 10 retain the row selections after changing Page, but not after filtering or sorting. |
Example 10 and 16 are the main demos, if that doesn't then I give up, seriously I spent over a week on this and it's quite frustrating to get it all to work together (filter + sort + pagination), it was working at some point, it might the code related to the pagination (that was a lot of code to put in to deal with local grid pagination). What you could try is to remove the pagination and I bet it will work. I seriously wish that I'd had more contributions on a lib that I spent few thousand of hours on. If you would take a look at, I would greatly appreciate the help. The problem, if it is with Pagination, would be in this function |
Nevermind, I found it after doing a quick search to see where the This const isSyncGridSelectionEnabled = this.gridStateService && this.gridStateService.needToPreserveRowSelection() || false;
if (!isSyncGridSelectionEnabled && this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector) {
this.gridService.setSelectedRows([]);
} should be this const isSyncGridSelectionEnabled = this.gridStateService && this.gridStateService.needToPreserveRowSelection() || false;
if (!isSyncGridSelectionEnabled && (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector)) {
this.gridService.setSelectedRows([]);
} I'll add another Cypress E2E test to make sure that test is also covered, forgot to check that possibility. |
... and of course I found yet another problem when using Local Grid Pagination and Filters. The filtered rows don't get removed from the selection array. Yet more complex code to deal with. This is so frustrating 😠 I just shouldn't have added this Local Grid Pagination, it's causing so much complexity everywhere to deal with. |
- a new property "filteredDataContextIds" was added to handle possible filtered data with row selection
after lot of effort, I think I finally got it all covered (works with/without Pagination too), however I had to add a new property in the Grid State to handle filtered and non-filtered row selections, the new prop is The output looks like this now, in most cases you'll probably want to use the new I'll push a new version tomorrow and hopefully this is the last time I go over this thing |
@timhawkins1 |
I've tried the latest version, and there still seems to be a problem. The row selection is retained correctly following filtering or sorting if It's possible to reproduce the problem in Example 10 if you edit the code so that |
@timhawkins1 I have to say though that next time around I'd like to get a bit more help in troubleshooting and/or testing, even just adding some Cypress E2E tests would have been helpful. This is an Open Source project for a reason, I'd like to have contributions once in a while (at least that was the reason of why we decided to make it Open Source). |
I confirm that it's working perfectly now, thank you! Point taken, I'm not very familiar with your code, but I was doing my best to be helpful by giving instructions to reproduce the problem. I'll try to make more of a contribution next time. |
I'm submitting a Bug report
Your Environment
Context
Setting syncGridSelection to TRUE does not preserve the row selections whenever I change the column filter. See #191
Expected Behavior
It should preserve the row selections if syncGridSelection is TRUE
Possible Solution
Probably can consider changing gridState.service.ts to something like below:
Code Sample
The text was updated successfully, but these errors were encountered: