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

SortDescriptors empty with Custom Ajax Binding

1 Answer 31 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.
Carling
Top achievements
Rank 2
Carling asked on 19 Jan 2012, 05:37 PM
Hi!

I'm using the custom ajax binding to my grid, and I have everything working except for sorting.  My GridCommand comes in with FilterDescriptors, but never any SortDescriptors.  I can see that the url has the queryparameters like "orderBy=Account-asc" but the command parameter never has any SortDescriptors.  I do do this manually like I am the page and pageSize, but I don't want to.  This should work, somehow.

My view:
@{ Html.Telerik().Grid(Model.vendor_accounts)
        .Name("SelectAccountsGrid")
        .EnableCustomBinding(true)
        .BindTo(Model.vendor_accounts)
        .Selectable(select => select.Enabled(true))
        .Columns(columns =>
        {
            columns.Bound(o => o.Account).Width(100).Title("Account Number");
            columns.Bound(o => o.Name).Width(180).Title("Name");
        })
        .DataBinding(dataBinding => dataBinding.Ajax()
                .Select("_SelectAccountsBinding", "ServiceAgreement", new { serviceAgreementId = serviceAgreementId }))
        .Scrollable(sc => sc.Height("300px"))
        .ColumnContextMenu()
        .Filterable()
        .Pageable(paging => paging.Style(GridPagerStyles.NextPreviousAndNumeric).Position(GridPagerPosition.Bottom).PageTo((int)ViewData["currentPage"]))
        .Sortable(sort => sort.Enabled(true))
        .Render();
}

And my controller:
[GridAction(EnableCustomBinding = true, GridName = "SelectAccountsGrid")]
public ActionResult _SelectAccountsBinding(GridCommand command,
                       int serviceAgreementId, int? page, int? size)
{
     var listRequest = new ContractService.ListRequest();
     var filters = new List<ContractService.SearchFilter>();
     var sorters = new List<ContractService.Sorter>();
 
     foreach (IFilterDescriptor filter in command.FilterDescriptors)
     {
         // Translate filter into my own
     }
      
     foreach (var sorter in command.SortDescriptors)
     {
         var serviceSorter = new ContractService.Sorter();
         serviceSorter.Member = sorter.Member;
 
         if (sorter.SortDirection == ListSortDirection.Descending)
             serviceSorter.Descending = true;
 
         sorters.Add(serviceSorter);
     }
 
     if (command.PageSize == 0 || command.Page == 0)
     {
         command.PageSize = size ?? 10;
         command.Page = page ?? 1;
     }
 
     listRequest.PageIndex = command.Page;
     listRequest.PageSize = command.PageSize;
     listRequest.SearchFilters = filters.ToArray();
     listRequest.Sorters = sorters.ToArray();
     string token = TokenService.GetToken(Session);
 
     var accountListData = GetMyAccounts(token, serviceAgreementId, listRequest);
     ViewData["Total"] = accountListData.VendorAccountTotal;
     ViewData["currentPage"] = listRequest.PageIndex;
 
     return View(new GridModel<ContractService.vendor_account>
     {
         Data = accountListData.vendor_accounts,
         Total = accountListData.VendorAccountTotal
     });
 }

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 23 Jan 2012, 09:53 AM
Hello Carling,

Generally speaking you should not have any problems retrieving the sorting descriptor property of the command argument. Our online demo implements how to apply the filtering,grouping and sorting when using Ajax custom binding. Please make sure that you covered all the steps listed there. If the problem persists please send an isolated project with your current logic and setup so we can investigate further.

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
Tags
Grid
Asked by
Carling
Top achievements
Rank 2
Answers by
Petur Subev
Telerik team
Share this question
or