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

Selecting a row on load of Syncfusion grid

Hi,

I am working on ASP .NET MVC4. In my view, left side partial view contains Syncfusion grid to display data and  on selecting any record in grid rendering partial views on right side. This is working fine upto now. If I pass SelectionId to View, I have to select a row and render partial views on load of grid.

Could you please help me on this?

This is very urgent for me. 

Thanks in advance.

Regards,
Siva

3 Replies

BM Bala Murugan A.S Syncfusion Team February 19, 2013 11:22 AM UTC

Hi SivaKumar,

Thanks for using Syncfusion Products.

We suggest you to use _selectRow property in OnLoad client side events to select row while on loading grid. Please refer the below code snippet.

[Grid1.cshtml]

.ClientSideEvents(events=>events.OnLoad("OnLoadGrid1"))

[JavaScript]

<script type="text/javascript">
    function OnLoadGrid1(sender, args) {
        sender._selectRow=2; // 2 - row index
    }
</script>

Please try the above code snippet and let us know if you have any concerns.

Regards,
Bala Murugan A.S


SI Sivakumar February 19, 2013 01:57 PM UTC

Hi Bala Murugan,

Thanks for the solution. But I do not know the row index to set on load of grid. I am just having SelectionId(Primary key of the Custom list, which is bind to grid). So using this Id how can I select a row on load of the grid?

Please help me on this?

Regards,
Sivakumar


BM Bala Murugan A.S Syncfusion Team February 28, 2013 03:58 AM UTC

Hi Sivakumar,

Thanks for your update.

We suggest you to pass row index which you want to select from controller to view through response header and select row based on the row index in using _selectRow attribute. Please refer the below code snippets.

[Code snippet]

public ActionResult Index(PagingParams par)

        {

            if (par.GridID == "Grid1")

            {

                var data1 = Employee.GetList();

                ViewData["GridData1"] = data1;

                //Get the index of the record which you want to select

                Response.AddHeader("RowIndex", data1.Select((obj, index) => new { obj.EmployeeID, Index = index }).SingleOrDefault(x => x.EmployeeID == 3).Index.ToString());

                return data1.GridJSONActions<Employee>();

            }

            else if (par.GridID == "Grid2")

            {

                var data1 = Employee.GetList();

                ViewData["GridData2"] = data1;

                //Get the index of the record which you want to select

                //Response.AddHeader("RowIndex", data1.Select((obj, index) => new { obj.EmployeeID, Index = index }).SingleOrDefault(x => x.EmployeeID == 3).Index.ToString());

                return data1.GridJSONActions<Employee>();

            }

            return View();

        }

 

[script]

<script type="text/javascript">

    $('#Grid1').ajaxSuccess(function (evt, request, settings) {

        var Index = request.getResponseHeader('RowIndex'); //get your data from response header

        if (Index != null) {

            var gridObj = $find('Grid1');

            gridObj._selectRow=Index;

 

        }

    });

</script>

Please let us know if you have any concerns.

Regards,

Bala Murugan A.S


Loader.
Live Chat Icon For mobile
Up arrow icon