Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current sort field in kendo grid?

I'm beginner... I'm using kendo-grid with Jquery.

I want to get current sorted field in kendo-gird.

I found this. console.log(grid.dataSource._sort[0].dir); console.log(grid.dataSource._sort[0].field);

Can I find alternative way?

this is my code.

        var dataSource = new kendo.data.DataSource({
        transport       : {
            read        : {
                type        : 'post',
                dataType    : 'json',
                contentType : 'application/json;charset=UTF-8',
                url         : cst.contextPath() + "/watcher/kendoPagination_statsErrorHistoryRetrieveQry.htm",
                data        : param
            },
            parameterMap: function (data, opperation) {
                return JSON.stringify(data);
            }
        },
        schema          : {
            data    : function(data) {
                return data;
            },
            total   : function(response) {
                return response.length > 0 ? response[0].TOTAL_COUNT : 0;
            }
        },
        pageSize        : cst.countPerPage(),
        serverPaging    : true,
        serverSorting   : true
    });

    var columns = kendoGridColumns();

    $("#grid")
        .kendoGrid({
            dataSource  : dataSource,
            sortable    : {
                mode : 'multiple',
                allowUnsort : true
            },
            columns     : columns.error()
            selectable  : 'row',
            scrollable  : true,
            resizable   : true,
        }));

How can I get current sorted field name?

like image 979
yhlee Avatar asked Oct 05 '16 04:10

yhlee


1 Answers

Avoid using private fields. The DataSource sort method is the official way to get the current sort state:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-sort

var dataSource = new kendo.data.DataSource({
  data: [
    { name: "Jane Doe", age: 30 },
    { name: "John Doe", age: 33 }
  ],
  sort: { field: "age", dir: "desc" }
});

var sort = dataSource.sort();

console.log(sort.length);   // displays "1"
console.log(sort[0].field); // displays "age"
like image 188
dimodi Avatar answered Oct 17 '22 23:10

dimodi