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

Default multi-sort on grid?

1 Answer 2104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 06 Dec 2013, 04:15 PM
So I have figured out how to give a grid a default sort order and it works good...  I would like to also be able to give it a secondary sort order...  first sort is "Bill Date" and then within rows that have the same bill date, they would be sort by "CoordinationOfBenefit".

Also of note, I have enabled multisort in the .Sortable

Thanks,
Jason



@(Html.Kendo().Grid<AccountClaim>()
                        .Scrollable(s => s.Height("auto"))
                        .Name("AccountClaimsGrid")
                        .HtmlAttributes(new { @class = "cursorLink", style= "height: 200px;" })
                        .DataSource(ds => ds.Ajax()
                            .Sort(sort => sort.Add("BillDate").Descending())
                            .Read("AccountClaimsData", "Workdriver", new { ProductName = ViewBag.SelectedProduct.ProductName, AccountId = Model.Account.AccountId })
                            //.PageSize(5)
                            .Events(e => e.Change("ClaimDataSourceChanged")))
                        .Columns(c =>
                        {
                            c.Bound(f => f.AccountClaimId).Visible(false);
                            c.Bound(f => f.ClaimNumber).Title("Claim Number").Width(125);
                            c.Bound(f => f.InsuranceCode).Title("Ins Code").Width(75);
                            c.Bound(f => f.CoordinationOfBenefit).Title("COB").Width(55);
                            c.Bound(f => f.ServiceDate).Title("Service").Format("{0:d}").Width(85);
                            c.Bound(f => f.BillDate).Title("Bill").Format("{0:d}").Width(85);
                            c.Bound(f => f.ClaimStatusRollupName).Title("Status").Width(100);
                            c.Bound(f => f.ClaimAmount).Title("Claim Amount").ClientTemplate("<span style='float: right;'>#=kendo.toString(ClaimAmount,'c')#</span>").Width(115);
                            c.Bound(f => f.PaidAmount).Title("Paid Amount").ClientTemplate("<span style='float: right;'>#=kendo.toString(PaidAmount,'c')#</span>").Width(110);
                            c.Bound(f => f.AdjustmentAmount).Title("Adjustment Amount").ClientTemplate("<span style='float: right;'>#=kendo.toString(AdjustmentAmount,'c')#</span>").Width(135);
                            c.Bound(f => f.PaidAmount).Title("Patient Amount").ClientTemplate("<span style='float: right;'>#=kendo.toString(PaidAmount,'c')#</span>").Width(125);
                        })
                        .Selectable(s => s.Mode(GridSelectionMode.Single))
                        .Sortable(s => s.SortMode(GridSortMode.MultipleColumn))
                        .Groupable(g =>
                        {
                            g.Messages(m =>
                            {
                                m.Empty("Drag Column Header Here to Group");
                            }
                            );
                        }
                            )
                        .Filterable()
                        .ColumnMenu()
                        .Events(e => e.Change("ClaimSelectionChanged"))
                    )

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 09 Dec 2013, 03:59 PM
Hello Jason,

You can define the sorting using a Statement lambda, for example: 
.DataSource(dataSource => dataSource
    .Ajax()
    .Sort(s =>
    {
        s.Add("BillDate").Descending();
        s.Add("CoordinationOfBenefit").Ascending();
 
    })


Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or