Reset everything after change data source

Hi,

How to reset the datagrid? I found some sample code as below. How about the columnchooser and searchbox?


let grid = document.getElementById("grid").ej2_instances[0];

grid.dataSource=null;

grid.clearGrouping();

grid.clearSorting();

grid.clearFiltering();

grid.clearSelection();

grid.clearGridActions();


4 Replies

MA Mohammed Ansar Sathik Ali Syncfusion Team May 6, 2022 03:47 PM UTC

Hi Kuan,


Greetings from the Syncfusion support.

Currently we are working your query and we will update further details on May 09 2022.

until then we appreciate your patience.

Regards,

Mohammed Ansar ,



MA Mohammed Ansar Sathik Ali Syncfusion Team May 9, 2022 01:31 PM UTC

Hi Kuan,


Greetings from Syncfusion support.


Query: Reset search and column chooser


By analyzing your query, you need to reset the search option value and column chooser. We reset search value by following method

  • Taking the Grid instance
  • Set the searchSetting.key to null


var gridObj = document.getElementById("Grid").ej2_instances[0];

gridObj.searchSettings.key ='';

 


We reset the column chooser by saving the columns value as object when it created and assign the object to column on reset


 

function created() {

  let gridObject = document.getElementById('Grid').ej2_instances[0];

  gridColumns = gridObject.columns.map((a) => Object.assign({}, a));

}

On button click function

  let gridObject = document.getElementById('Grid').ej2_instances[0];

  gridObject.columns = gridColumns.map((a) => Object.assign({}, a));

 


We attached a sample with it for your convenience


Please get back to us if you need further assistance on this.


Regards,

Mohammed Ansar ,


Attachment: resetCore_bf45b0eb.zip


KL Kuan Long Khiu May 10, 2022 02:07 AM UTC

Hi Mohammed Ansar,


It works perfectly. Thanks for your help.


Regards,

Kuan Long



MA Mohammed Ansar Sathik Ali Syncfusion Team May 10, 2022 07:09 AM UTC

Hi Kuan,


Most welcome,


we are glad to hear that the solution works.



Please get back to us if you need any assistance.


Regards,

Mohammed Ansar ,


Loader.
Up arrow icon