Dynamic Data with different column name

I am using EJ2 asp.net core data grid. 

Now i am firing query from textarea like 'select * from students' now data comes from rows and cols in json it how can we display that data with syncfusion grid control. 

Here text area is query editor so we can write any query like 

select * from students

select * from employees

select * from departments. 


so every time result would have different column name. how to load any data generic data to grid with dynamic columns and rows. 


Thanks.


1 Reply

PS Pavithra Subramaniyam Syncfusion Team November 28, 2022 06:46 AM UTC

Hi Hiral,


From your query, we understand that you want to set the Grid dataSource with dynamic columns. If yes,
you can achieve your requirement by setting the “columns” and “dataSource” properties. Please refer to the below code example for more information.


In the below code, we have set the Grid dataSource and columns inside our AJAX request as an example.


        let ajax = new ej.base.Ajax();

        ajax.type = "POST"

        ajax.url = "Home/getData"

        ajax.send();

        ajax.onSuccess = (result) => {

             var grid = document.getElementByID('Grid').ej2_instances[0]; //here “Grid” is DataGrid id

             grid.columns = [];

            grid.dataSource = result;

        }

 


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


Regards,

Pavithra S


Loader.
Up arrow icon