This question is locked. New answers and comments are not allowed.
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:
And my controller:
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
});
}