Kendo UI grid set selected row

2 posts, 0 answers
  1. santhosh
    santhosh avatar
    3 posts
    Member since:
    Oct 2013

    Posted 14 Nov 2013 Link to this post


     I have list of users (List<User>) binded to a grid. I have a currently logged in user information in ViewData[User]. 
    What I want is if a grid contains a user which is in ViewData. I want that user to be selected as soon as grid loads data. How can I do this validation ? How can I get currently selected row ?

    .DataSource(dataSource => dataSource  
    .Ajax() // Specify that ajax binding is used
    .Read(read => read.Action("User_Read", "Home")) // Set the action method which will return the data in JSON format
    .Columns(columns =>
    columns.Bound(user=> user.UserID); 
    columns.Bound(user=> user.UserName); 
    columns.Bound(user=> user.City);;
    .Pageable() // Enable paging
    .Sortable() // Enable sorting
  2. Ignacio
    Ignacio avatar
    46 posts
    Member since:
    Feb 2013

    Posted 14 Nov 2013 Link to this post

    I would suggest you store a primitive (like Username) instead of the whole User object on your ViewBag.

    If you do this it shouldnt be hard to:

    • Store the Username on a javascript variable. (var name = "@ViewBag.Username";)
    • Subscribe to the DataBound event on the grid.
    • Use jQuery to find the row to select based on the data of a cell or a data attribute you add to it.
    • Use the select method on the grid on that found row to select it.
Back to Top