Specifying default sort in grid

白昼怎懂夜的黑 提交于 2019-12-14 03:52:33

问题


Is it possible to specify a default sort when using the knockout-kendo binding to bind the Telerik Kendo grid?

I am binding the grid like this:

kendoGrid: { data: grid.Rows, sortable: {allowUnsort: false,mode:'single'}, columns: grid.Columns} 

However, I have not found a way to specify the default sort. Standard Kendo has a sort:{field:"Col1",dir:"asc"} element that can be specified on the data source, but it's unclear how this can be applied to the kendoGrid binding

Default Kendo sort element: http://docs.telerik.com/kendo-ui/api/framework/datasource#sort-array--objectdefault


回答1:


The comments from the following answer gave me a clue:

What is the difference between the data and dataSource in knockout-kendo grid widget?

It seems like you can use data and dataSource in tandem if you want to specify this behavior:

kendoGrid: {dataSource:{sort:{field:'Col1',dir:'asc'}}, data: grid.Rows, sortable: {allowUnsort: false,mode:'single'}, columns: grid.Columns}



回答2:


Check out the following post in the kendo forums.

http://www.telerik.com/forums/default-sort-for-kendo-grid-mvc

.DataSource(dataSource => dataSource
        .Ajax()
        .Sort(sort => sort.Add("City").Ascending()) // <-- initial sort expression
        .Read(read => read.Action("Index", "Home"))
    )


来源:https://stackoverflow.com/questions/23393506/specifying-default-sort-in-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!