This question is locked. New answers and comments are not allowed.
when i use ajax binding and filter in my grid, i can,t get the FilterDescriptors in my controller.
the view:
@(Html.Telerik().Grid<UserModel>(Model.UserModels.Data)
.Name("user-list")
.Columns(columns =>
{
columns.Bound(x => x.Username).Width(50).Filterable(false);
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("Refresh", "User"))
.Filterable(filtering => filtering.Filters(filters =>
{
// username
if (!String.IsNullOrEmpty(ViewData["searchUsername"] as string))
{
filters.Add(x => x.SearchUsername).Contains((string)ViewData["searchUsername"]);
}
}))
.Pageable(settings => settings.Total(Model.UserModels.Total).PageSize(1).Position(GridPagerPosition.Both))
.EnableCustomBinding(true)
)
and the controller:
[HttpPost, GridAction(EnableCustomBinding = true)]
public ActionResult Refresh(GridCommand command)
{
string searchUsername = command.FilterDescriptors.GetValueFromFilters("searchUsername");
var users = _accountService.GetUsers(searchRoleIds.ToArray(), searchUsername, command.Page - 1, command.PageSize);
var gridModel = new GridModel<UserModel>
{
Data = users.Select(u => { return Map(u); }),
Total = users.TotalCount
};
return new JsonResult
{
Data = gridModel
};
}
the problem is the command.FilterDescriptors.count always is 0. but i turely add the "searchUsername"into the FilterDescriptors
,is it a bug?
and it's the same problem at http://www.telerik.com/community/forums/aspnet-mvc/grid/bug-initial-filter-with-ajax-binding.aspx
the view:
@(Html.Telerik().Grid<UserModel>(Model.UserModels.Data)
.Name("user-list")
.Columns(columns =>
{
columns.Bound(x => x.Username).Width(50).Filterable(false);
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("Refresh", "User"))
.Filterable(filtering => filtering.Filters(filters =>
{
// username
if (!String.IsNullOrEmpty(ViewData["searchUsername"] as string))
{
filters.Add(x => x.SearchUsername).Contains((string)ViewData["searchUsername"]);
}
}))
.Pageable(settings => settings.Total(Model.UserModels.Total).PageSize(1).Position(GridPagerPosition.Both))
.EnableCustomBinding(true)
)
and the controller:
[HttpPost, GridAction(EnableCustomBinding = true)]
public ActionResult Refresh(GridCommand command)
{
string searchUsername = command.FilterDescriptors.GetValueFromFilters("searchUsername");
var users = _accountService.GetUsers(searchRoleIds.ToArray(), searchUsername, command.Page - 1, command.PageSize);
var gridModel = new GridModel<UserModel>
{
Data = users.Select(u => { return Map(u); }),
Total = users.TotalCount
};
return new JsonResult
{
Data = gridModel
};
}
the problem is the command.FilterDescriptors.count always is 0. but i turely add the "searchUsername"into the FilterDescriptors
,is it a bug?
and it's the same problem at http://www.telerik.com/community/forums/aspnet-mvc/grid/bug-initial-filter-with-ajax-binding.aspx