This is a migrated thread and some comments may be shown as answers.

[Solved] MVC Grid - Dynamically Select Row

2 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 1
David asked on 06 Sep 2011, 10:24 PM
Is there a way to programatically select a row in the grid?

Specifically, the request is to have a "Next" button that selects the next record in the grid.  This may eventually be rolled into the "Save" button (so when the user clicks the "Save" button, it saves the current record and moves on to the next one).

Is this even possible?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 07 Sep 2011, 06:59 AM
Hi David,

The Grid selection is purely visual, so the only thing you need to do is append a t-state-selected CSS class to the desired <tr> element. You can use standard DOM operations or jQuery to accomplish this, given you have a "current" row available.

http://api.jquery.com/next/

You can even trigger edit mode for a specific row by executing click() on the Edit button inside the row.

$(".t-grid-edit", r).click()

where "r" is a Grid table row DOM element or a jQuery object.

Regards,
Dimo
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
David
Top achievements
Rank 1
answered on 07 Sep 2011, 03:02 PM
Thanks!  That worked!

If anyone else runs into this, here is my complete code.

function selectNextRow() {
    var selectedrow = $(".t-state-selected");
    //var id = $(".t-state-selected :first-child").text(); -- CURRENT ID
    var nextRow = $(".t-state-selected").next();
    var id = nextRow.children().first().text();
    selectedrow.removeClass("t-state-selected");
    nextRow.addClass("t-state-selected");
    //YOUR FUNCTION HERE
}
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Dimo
Telerik team
David
Top achievements
Rank 1
Share this question
or