We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Persist selection and the GridComponent

Hi,

We are using the GridComponent.

When we replace the data source we want to be able to keep the selection state.
We have enabled persistSelection and set column[0] to primaryKey.
 
When the data source is replaced after an update, nothing or everything is selected in the GridComponent.

Is there an event or some other way to eneable for the selection to be persistant when the data source replaced.
We have single selection.

BR
Niklas Sturfelt
Geometra Software AB


3 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team June 12, 2019 05:20 PM UTC

Hi Niklas, 

Thanks for contacting Syncfusion Support. 

Query#:- Is there an event or some other way to enable for the selection to be persistant when the data source replaced. 

We have checked your query and to achieve your requirement we need to get the selected row index using rowSelected event of the Grid. In the rowSelected event of the Grid, we can get the index and while updating the dataSource we need to update the index through selectRows method of the Grid. 
Please refer to the code example:- 

var index; 
      $(function () { 
             $("#Grid").ejGrid({ 
                    dataSource: Data, 
                    allowPaging: true, 
                    commonWidth: 200, 
                    enablePersistence: true, 
                    rowSelected: "rowSelected", 
                    actionComplete: "complete", 
 
                     
                    columns: [ 
                        { field: "OrderID", isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, validationRules: { required: true, number: true } }, 
                        { field: "CustomerID", headerText: 'Customer ID', validationRules: { required: true, minlength: 3 } }, 
 
                    ] 
                }); 
            }); 
 
            function rowSelected(args) { 
                index = args.rowIndex; 
              } 
 
            function refreshData(){ 
            var gridObj = $("#Grid").ejGrid("instance"); 
            gridObj.dataSource(window.gridData); 
            gridObj.selectRows(index); 
        } 

Refer to the API Link:- 

Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 
 



NS Niklas Sturfelt June 13, 2019 12:18 PM UTC

Hi again,

I have tried what you have suggested and I seem to be able to keep the selection in the grid.

The problem is however, that it does not seem possible to hinder the rowSelected event from being triggered 
when the selectRows call is made in the actionComplete callback.

Is there a way to temporarily disable the rowSelected event when a selectRows call is made?

BR
Niklas Sturfelt
Geometra Software AB


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team June 14, 2019 03:35 PM UTC

Hi Niklas, 

Query#:I s there a way to temporarily disable the rowSelected event when a selectRows call is made? 
 
We have checked your query and while using selectRows method or while selecting the records, rowSelected event gets triggered by default. As this was default behavior we cannot prevent the event. Could you please let us know for which purpose you need to prevent the event? 
 
Based on your requirement, we can disable and provide you solution. 
 
Regards, 
Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon