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. Image for the cookie policy date

Selected Row

Dear All,
I'm a newbie regarding this component.
I need to have the key associated to selected row of a grid and disply it into an input text.
On change of selected row the value will be change.
How can I retrieve this information?
Regards Lorenza


1 Reply

BM Balaji Marimuthu Syncfusion Team June 22, 2015 11:13 AM UTC

Hi lorenza,

Thanks for using Syncfusion Products.

The requested requirement can be achieved by using the client side event RowSelected. Please find a sample and code example as below:
Sample: MvcApplication17

<input type="text" id="txtbox"/>


@(Html.EJ().Grid<MvcApplication17.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        .AllowScrolling()

         .AllowPaging()    /*Paging Enabled*/

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();

            col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add();

            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();

        })

        .ClientSideEvents(eve=> eve.RowSelected("rowselected"))

        )




The RowSelected event will be triggered after a row has been selected and we can get the selected records values by using the method getSelectedRecords.

<script>

    function rowselected(args) {

        var index= this.selectedRowsIndexes; //you can get the selected row index values

        var selectedval = this.getSelectedRecords()[0].OrderID;   //get the selected records values

        $("#txtbox").val(selectedval);

      

    }
</script>


We have displayed the selected records OrderID value to the input text box. Please refer the documentation for more details about rowSelected event and getSelectedRecords method in the following links

RowSelected Event: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#event:rowSelected
getSelectedRecord Method: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#getSelectedRecords

Please let us know if you have any queries.

Regards,
Balaji Marimuthu

Loader.
Live Chat Icon For mobile
Up arrow icon