)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to get selected row indexes in Grid

Platform: jQuery |
Control: ejGrid |
Published Date: February 16, 2016 |
Last Revised Date: August 5, 2019

Solution:

You can get the selected row indexes by using the selectedRowsIndexes property in Grid. The following code example shows how to get the selected row indexes in Grid.                              1.  Render the Grid control.

 

JS

<div id="Grid"></div>
<script type="text/javascript">
    $(function () {// Document is ready.        
        $("#Grid").ejGrid({
            dataSource: window.gridData, 
            allowPaging: true,
            allowSelection: true,
            selectionType: "multiple",
            columns: [
                      { field: "OrderID", headerText: "Order ID, width: 100},
                      { field: "CustomerID", headerText: "Customer ID", width: 100 },
                      { field: "Freight", headerText: "Freight", width: 100, format: "{0:C}" },                      
                      { field: "ShipCountry", headerText: "Ship Country", width: 100 },                      
            ],
           rowSelected: "rowSelected",
         });
    });
</script>

 

MVC

[In View]
@(Html.EJ().Grid<object>("Grid")            
            .Datasource((IEnumerable<object>)ViewBag.data))
            .AllowPaging() 
            .AllowSelection()
            .SelectionType(SelectionType.Multiple) 
       })
            .Columns(col =>
            {                    
                col.Field("OrderID").HeaderText("Order ID").Width(100).Add();
                col.Field("CustomerID").HeaderText("Customer ID").Width(100).Add();                
                col.Field("Freight").Width(100).Format("{0:C").Add();                
                col.Field("ShipCountry").HeaderText("Ship Country").Width(100).Add();                
            })
            .ClientSideEvents(eve=>eve.rowSelected ("rowSelected"))
)
 

 

[Controller]
namespace EJGrid.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var DataSource = OrderRepository.GetAllRecords();
            ViewBag.data = DataSource;
            return View();
        }        
    }
}

 

ASP.NET

[aspx]
<ej:Grid ID="Grid" runat="server" AllowPaging="True" 
AllowSelection="True" SelectionType="Multiple" >  
            <ClientSideEvents rowSelected="rowSelected" />
            <Columns>
                <ej:Column Field="OrderID" HeaderText="Order ID"  Width="100"/>                
                <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="100"/>
                <ej:Column Field="Freight" HeaderText="Freight" Format="{0:C}" Width="100"/> 
                <ej:Column Field="ShipCountry" HeaderText="Ship Country" Width="100"/>                
            </Columns>
</ej:Grid>  
 

 

 

 

[CS]
public partial class _Default : Page
{    
    protected void Page_Load(object sender, EventArgs e)
    {
            this.Grid.DataSource = new NorthwindDataContext().Orders. ToList();
            this.Grid.DataBind();
    }
}

 

 

 

 

 

 

 

2. You can get the selectedRowsIndexes in rowSelected event, which triggered after a row is selected and get the selected records by using getSelectedRecords method

JS

 

function rowSelected(args) { 
            var selectedrowindex = this.selectedRowsIndexes;  // get selected row indexes             
            alert(selectedrowindex);
            var selectedrecords = this.getSelectedRecords();  // get selected records   
   }

 

 

 

 

 

 

 

 

 

 

 

 The following output is displayed as a result of the above code example.

rowselect example

Figure: Select the rowIndexes by rowSelected Event

 

ADD COMMENT
You must log in to leave a comment
Comments
Sunil patra
Jan 16, 2018

TypeError: $(...).ejGrid is not a function

what i need to do to resolve this


Reply
Farveen Sulthana Thameeztheen Basha [Syncfusion]
Jan 17, 2018

Hi Sunil,

 

The reported problem “TypeError: $(...).ejGrid is not a function” occurs when we doesn’t refer the script Files necessary to render the Grid control. The following libraries are important to render “Grid” component.   

 

1. jquery

2. Jsrender

3. ej.web.all.min.

 

<head>

   <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta name="description" content="Essential Studio for JavaScript">

    <meta name="author" content="Syncfusion">

    <title>title>

   

    <link rel="stylesheet" rel='nofollow' href="http://cdn.syncfusion.com/13.2.0.29/js/web/flat-azure/ej.web.all.min.css" />

 

   

    <script src="https://code.jquery.com/jquery-3.1.1.min.js">script>

   <script src="http://cdn.syncfusion.com/js/assets/external/jsrender.min.js">script>

    <script src="http://cdn.syncfusion.com/15.1.0.33/js/web/ej.web.all.min.js"> script>

 

   

 

head>

<body>

 

body>

html>

 

Please ensure that you have referred above mentioned script files in your sample.

 

Instead of referring ej.web.all.min.js” , you can also refer the individual script files to render the Grid control.

 

Please refer to this document for referring the individual grid dependencies

 

Grid dependencies : https://help.syncfusion.com/js/grid/getting-started

 

The Custom Script Generator (CSG) utility is helps to generate the Grid individual script file. We can generate file for any Essential Studio Version . find the CSG online link: 

CSG : http://csg.syncfusion.com/

 

Refer to the following update document for more information on the Essential JS Custom Script Generator . 

CSG Getting-Started : http://help.syncfusion.com/js/custom-script-generator

 

Also ensure that there has been any Jquery conflicts  in your sample.

 

After following above solution still facing issue please get back to us with further details.

 

Regards,

 

Farveen sulthana T

 

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon