pre-selecting cells at grid render

Hi, 

I have a grid with several columns - one of them is a checkbox column and I want to pre-select specific cells(checkbox cells) at grid render. 

I tried it with the ISelectedCell[] inside this.gridInstance.selectCells() in rowDataBound by different ways, but it does not work. 

Can you give me please an working solution example of this issue.

Kind Regards


3 Replies

SK Sujith Kumar Rajkumar Syncfusion Team August 13, 2021 07:29 AM UTC

Hi Andreas, 
 
Greetings from Syncfusion support. 
 
Based on the query we suspect that your requirement is to select multiple Grid cells on initial render. If so, you can achieve it by passing the required row and cell indexes to be selected to the Grid’s selectCells method in the dataBound event handler(triggers on Grid data bind). A global flag variable is used here to ensure this case is executed only once(since the dataBound event will be triggered each time the Grid data is modified). 
 
This is demonstrated in the below code snippet, 
 
// Grid’s databound event handler 
onDataBound() {  
         // This event will be triggered each time the grid data is modified, so flag variable is used so that this case is executed only on Grid initial render 
    if (this.initialRender) { 
        this.initialRender = false; 
        // The required cell indexes to be selected are passed to the selectCells method 
        this.gridInstance.selectCells([{rowIndex: 0, cellIndexes: [0]}, {rowIndex: 2, cellIndexes: [0, 2]}]) 
    } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
 
If we misunderstood your query or if you require any further assistance, then please get back to us. 
 
Regards, 
Sujith R 



AW Andreas Weber August 13, 2021 09:12 AM UTC

Thank you for the fast reply.

Now I have another issue. I want to use batchEdit including dropdownedit in the same grid, based on cellSelection. I am assuming that a double click to open the dropdown in batchedit has no effect on other cells, especially on the checkbox cells, but it has. I'm using exclusively cellSelection in this Grid. 


A maybe similar effect can be seen in the example you sent. If I hold the mouse button down on one cell and switch in one direction, it also effects the checkbox cells. 


Is there a possibility in batchEdit settings to handle that it has no effect on other cells?



SK Sujith Kumar Rajkumar Syncfusion Team August 16, 2021 10:40 AM UTC

Hi Andreas, 
 
Based on the provided information we suspect that your requirement is to maintain the cell selection while performing batch edit. If so, we would like to let you know that when batch edit is started, the previous selections will be cleared. This is the default behavior of the Grid in its current architecture and it is not feasible to maintain the selection for this case. 
 
If this is not your query and your requirement is to maintain the cell selection once the batch edit is completed or any other case, then please let us know based on which we will validate from our end and provide the further details. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon