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

[Solved] Filter problem in grid control!

0 Answers 103 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.
xu
Top achievements
Rank 1
xu asked on 09 Dec 2011, 06:20 AM
code in my view:
@(Html.Telerik().Grid<UserModel>(Model.UserModels.Data)
.Name("user-list")
.Columns(columns =>
{
columns.Bound(x => x.Id).Width(5).Filterable(false);
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"]);
}
}))
.EnableCustomBinding(true)
)
and code in my controller:
[HttpPost, GridAction(EnableCustomBinding = true)]
public ActionResult Refresh(GridCommand command)
{
string searchUsername = command.FilterDescriptors.GetValueFromFilters("searchUsername");
var users = _accountService.GetUsers( searchUsername);
var gridModel = new GridModel<UserModel>
{
Data = users.Select(u => { return Map(u); }),
Total = users.Count
};
return new JsonResult
{
Data = gridModel
};
}

my problem is :
in my view, i have add the SearchUsername to filters, and FilterDescriptors.count = 1;
but when the code comes to Refresh(),
command.FilterDescriptors.count = 0, can't get the ViewData["searchUsername"],

what's the problem? thanks!
Tags
Grid
Asked by
xu
Top achievements
Rank 1
Share this question
or