0

I am using Angular SLickgrid and want to show all the checkboxes for all rows & also header row checkbox as selected by default (when grid loads). I am able to achieve it partly by using this.angularGrid.gridService.setSelectedRows(this.allDataId) but I am getting errors in console and all data rows are not visible. I cannot use preset because I want to show all rows selected & till the time angular grid is loaded, I don't have all row IDs. Below is the error that I am getting. I have added null checks before passing data to setSelectedRows() but no use.

TypeError: Cannot read property 'children' of null
    at ensureCellNodesInRowsCache (dist/data.bundle.js.gz:2692)
    at getCellNode (dist/data.bundle.js.gz:2692)
    at updateCellCssStylesOnRenderedRows (dist/data.bundle.js.gz:2692)
    at setCellCssStyles (/dist/data.bundle.js.gz:2692)
    at Event.handleSelectedRangesChanged (/dist/data.bundle.js.gz:2692)
    at Event.notify (/dist/data.bundle.js.gz:2674)
    at RowSelectionModel.p [as setSelectedRanges] (/dist/data.bundle.js.gz:2692)
    at SlickGrid.setSelectedRows (/dist/data.bundle.js.gz:2692)
    at SlickGrid.m (/dist/data.bundle.js.gz:2692)
    at Event.notify (/dist/data.bundle.js.gz:2674)

Please suggest how to achieve it. Thanks.

aks1993
  • 3
  • 1

1 Answers1

0

The answer, if that is an acceptable one, is in your question. The SlickGrid Row Selection plugin is not meant to be all selected at first so you have to stick with using setSelectedRows and if you don't have all Ids at hand then call it when you do... and in case you're pushing data in chunk, then call setSelectedRows on each chunk. There's no magic here, you need to call it when you have the correct Ids

ghiscoding
  • 12,308
  • 6
  • 69
  • 112
  • It should, why don't you just give it a try? – ghiscoding Feb 15 '21 at 12:55
  • I am trying the same but not working for tree data. If I gave hardcoded data like 1,2,3,4...,10 then it is preselecting but if I am giving further row indexes then also I am getting above errors. Is it something data specific? selectedRows() just expects row Indexes right? – aks1993 Feb 15 '21 at 13:17
  • `setSelectedRows` is row indexes in the grid AND current page, you didn't mention that you use page but you said it happens when you go over 10. We can't help you if you aren't providing more info to your question. – ghiscoding Feb 15 '21 at 13:53