i can't get the grid object

At first at worked with EJ1 grid but now i décided to implement the EJ2 grid so:

my grid plugin is:

@Html.EJS().Grid("FlatGrid").DataSource((System.Data.DataTable)ViewBag.DataSource).Columns((List<Syncfusion.EJ2.Grids.GridColumn>)ViewBag.cols).EnableVirtualization().AllowResizing(true).Height("700").Width("auto").AllowFiltering().AllowSorting().AllowSelection().FilterSettings(filter =>
{ filter.Type(Syncfusion.EJ2.Grids.FilterType.Excel); }).ToolbarClick("toolbarClick").Toolbar(toolbarItems).Render()
 
With EJ1 i wrote the following  two lignes to get the index of the selected row when i did this with my new grid i get undifined in my variable gridObject.

var gridObject = $.extend(true, {}, $("#FlatGrid").data("ejGrid"));
var rowIndex = gridObject.model.selectedRowIndex;

How can i get the index with EJ2.

1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team June 22, 2018 12:02 PM UTC

Hi Bassem, 


Thanks for using Syncfusion products. 


Query #1:’How to get a grid instance in EJ2’ 
 
Syncfusion Essential JS 2 controls are not dependent on jQuery plugins. So, we can get the instances from like as follows, 

function buttonClick(args) { 
 
        var gridInstance = document.getElementById("FlatGrid").ej2_instances[0]; //create a grid instance 
 
    } 


Query #2:’Get row index for selected records’ 

We have built-in API to get a selected row index for Grid. Please refer to the following code example and Help documentation, 

Code example: 
function buttonClick(args) { 
 
        var gridInstance = document.getElementById("FlatGrid").ej2_instances[0]; //create a grid instance 
        var selectedRowIndex = gridInstance.getselectedrowindexes(); //here we can get the selected row index 
    } 
 
Help documentation: 


Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon