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

ajax binding and FilterDescriptors problem

6 Answers 62 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 13 Dec 2011, 01:18 PM
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

6 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 14 Dec 2011, 11:44 AM
Hello Xu,

You can set the ActionParameterName in the controller's GridAction attribute so it matches the name of the parameter in the Action's signature
e.g.

[GridAction(ActionParameterName ="command",EnableCustomBinding=true)]
        public ActionResult Refresh(GridCommand command)

I hope this helps.

Best wishes,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
xu
Top achievements
Rank 1
answered on 15 Dec 2011, 02:43 AM
thank you!

but it does't work.
0
Petur Subev
Telerik team
answered on 16 Dec 2011, 03:28 PM
Hello Xu,

As examining your code I noticed that you are using Custom Ajax binding and also you initially populate the Grid by passing a collection to the constructor. Doing so wont trigger the custom binding in your select Grid Action since the Action method is not being called the first time.
I attached a demo project which implements a Grid using custom Ajax binding and successfully  retrieves the filter descriptors in the action method.
If this doesn't help you to find out where the problem comes, please reproduce the scenario by modifying the attached project and send it back so we can check it.

Kind regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
xu
Top achievements
Rank 1
answered on 19 Dec 2011, 09:28 AM
thanks you very much!!
i send my project and have remove any insignificant code, so you can find the problem easily .
now use any  username which does not exist to search will get the problem.

thank you for your patient reply!
0
Petur Subev
Telerik team
answered on 20 Dec 2011, 03:46 PM
Hello Xu,

You are unable to receive this filter descriptor because the property you apply to is not bound to a column.
To make things work you can add a hidden column bound to this property.
e.g.

//..
.Columns(columns =>
                {
                    columns.Bound(x => x.SearchUsername).Hidden(true);
//..



All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
xu
Top achievements
Rank 1
answered on 21 Dec 2011, 06:25 AM
thank you!!!, it solves!
Tags
Grid
Asked by
xu
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
xu
Top achievements
Rank 1
Share this question
or