Ej2 Grid: It seems Grid dataBound event handler is called twice?

Hello,

It seems Grid dataBound is called twice? is it default behavior?



Best regards,

Ismail


5 Replies 1 reply marked as answer

VS Vignesh Sivagnanam Syncfusion Team August 23, 2021 01:15 PM UTC

Hi ISMAIL 

Greetings from Syncfusion support 

Based on your query, we found that you have faced issue that the EJ2 Grid dataBound event is triggered twice. Based on your query, we have validated the reported issue at our end and the dataBound event is  triggered at once. 
  
Please refer the below sample and screenshot for your reference, 


 

If your still faced the reported issue at your end, please share the below details to validate further, 

1. If possible share the issue reproduced sample or replicate the issue in the above sample. 

2. Share the full grid rendering code. 

3. Syncfusion package version. 

Please get back to us for further assistance 

Regards 
Vignesh Sivagnanam 



IH ISMAIL HAMZAH replied to Vignesh Sivagnanam August 24, 2021 01:42 AM UTC

Hello Vignesh,


By using your code, I have replicate the issue:




import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);

import { GridSelection } from '@syncfusion/ej2-grids';
import { QueryDataManager } from '@syncfusion/ej2-data';
import { orderData } from './data-source';

Grid.Inject(Selection);

/**
 * Default Grid sample
 */
function datobound(argsany): void {
  console.log('datobound is triggered');
}



let dataObject = new DataManager(orderData as JSON[]).executeLocal(
  new Query().take(15)
);
let gridGrid = new Grid({
  columns: [
    {
      field: 'OrderID',
      headerText: 'Order ID',
      width: 120,
      textAlign: 'Right'
    },
    { field: 'CustomerName'headerText: 'Customer Name'width: 150 },
    {
      field: 'OrderDate',
      headerText: 'Order Date',
      width: 130,
      format: 'yMd',
      textAlign: 'Right'
    },
    { field: 'Freight'width: 120format: 'C2'textAlign: 'Right' },
    {
      field: 'ShippedDate',
      headerText: 'Shipped Date',
      width: 140,
      format: 'yMd',
      textAlign: 'Right'
    },
    { field: 'ShipCountry'headerText: 'Ship Country'width: 150 }
  ],
  dataBound: datobound
});

loadGrid();

function loadGrid(){  
grid.appendTo('#Grid');
grid.dataSource = data;
}








VS Vignesh Sivagnanam Syncfusion Team August 24, 2021 12:46 PM UTC

Hi ISMAIL 

Thanks for the update 

Based on your query, we have validated your code example and our end and found that you have append the grid inside the function and provide the grid dataSource dynamically after appending the grid. The EJ2 Grid’s dataBound event is triggered due to the appending of dataSource dynamically after the grid component is created.  

To resolve the issue at your end, we suggest you to provide datasource before grid append. 

Please refer the below code example for your reference,  

function loadGrid() { 
  grid.dataSource = data; 
  grid.appendTo('#Grid'); 
} 

Please get back to us for further assistance, 

Regards 
Vignesh Sivagnanam 


Marked as answer

IH ISMAIL HAMZAH replied to Vignesh Sivagnanam August 24, 2021 01:55 PM UTC

Hello Vignesh,


Thank you for your update. The solution you provide, successfully solve the problem.


Thank you for your help and support.


Best regards,

Ismail



VS Vignesh Sivagnanam Syncfusion Team August 25, 2021 01:38 PM UTC

Hi ISMAIL 

Thanks for the update 

We are happy to hear that the provided solution works fine at your end. 

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

Regards, 
Vignesh Sivagnanam 


Loader.
Up arrow icon