Reputation: 77
I have a list of users, List of 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 ?
@(Html.Kendo().Grid(KendoGridAjaxBinding.Models.User)()
.Name("grid")
.DataSource(dataSource => dataSource .Ajax()
.Read(read => read.Action("User_Read", "Home"))
.Columns(columns => {
columns.Bound(user=> user.UserID);
columns.Bound(user=> user.UserName);
columns.Bound(user=> user.City);
).Pageable().Sortable())
Upvotes: 0
Views: 1366
Reputation: 473
To pre select a row you can try with this code in the grid:
.RowAction(row =>
{
if (condition)
{
row.HtmlAttributes["class"] = "k-state-selected";
}
})
And to get the selected row you can call a JavaScript function like this if you are editing:
function editItem(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
//the dataItem will be the user model
}
or take a look at this post of Kendo
Upvotes: 1