【问题标题】:How to get current sort field in kendo grid?如何在剑道网格中获取当前排序字段?
【发布时间】:2016-10-05 04:46:58
【问题描述】:

我是初学者... 我在 Jquery 中使用剑道网格。

我想在 kendo-gird 中获取当前排序的字段。

我找到了这个。 console.log(grid.dataSource._sort[0].dir); console.log(grid.dataSource._sort[0].field);

我能找到其他方法吗?

这是我的代码。

        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,
        }));

如何获取当前排序的字段名称?

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    避免使用私有字段。 DataSourcesort方法是官方获取当前排序状态的方法:

    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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多