Dynamically create a new Grid on clicking a Button

Hey, hi.

I was looking through documentation and forums to find out how to create a new grid dynamically, when a user clicks on a button saying "Add new grid", but couldn't find any.

My Use case requirement:

There's already a grid present in the View, and when a user clicks on "Add new Grid", I should be able to create a new Grid cloning the existing one but just changing the id.

I found one in Angular, where someone asked a similar query and there's a solution provided in javascript. But when I tried to replicate the same, the required libraries are not found.

Can you guys help me in creating the same functionality but in .net Core's View ?

The Angular thread I was referring to:

https://www.syncfusion.com/forums/171391/dynamically-make-a-new-grid-on-button-press


1 Reply 1 reply marked as answer

PS Pavithra Subramaniyam Syncfusion Team May 18, 2022 03:22 PM UTC

Hi Krishna,


Thanks for contacting Syncfusion support.


You can render a dynamic Grid in the view page by using the JavaScript Grid using the ES5 script. Please refer to the below code example and getting started page for more information.


function bindGridJSFn(e) {

  var grid = new ej.grids.Grid({

    allowPaging: true,

    dataSource: data,

    columns: [

      { field: 'OrderID', headerText: 'Order ID', width: 100 },

      { field: 'Freight', headerText: 'Freight', width: 100 },

      { field: 'CustomerID', headerText: 'Customer Name', width: 100 },

    ],

  });

  grid.appendTo('#myGrid');

}

 


https://ej2.syncfusion.com/javascript/documentation/grid/getting-started/#adding-grid-control


Please get back to us if you need further assistance.


Regards,

Pavithra S


Marked as answer
Loader.
Up arrow icon