2016-12-01 268 views
0

我们有一列显示在文本中,但排序应该是数字。Kendo Grid排序不同的顺序

是否可以通过可自定义的顺序在Kendo UI网格中对可排序的列进行排序,在我的情况下是通过数字字段进行排序?

回答

1

您应该能够使用的列的sortable.compare功能:http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.sortable.compare

<div id="grid"></div> 
<script> 
var numbers = { 
    "one" : "a", 
    "two" : "b", 
    "three": "c" 
}; 

var dataSource = new kendo.data.DataSource({ 
    data: [ 
     { id: 1, item: "two" }, 
     { id: 2, item: "one" }, 
     { id: 3, item: "three" } 
    ] 
}); 

$("#grid").kendoGrid({ 
    dataSource: dataSource, 
    sortable: true, 
    columns: [{ 
     field: "item", 
     sortable: { 
      compare: function(a, b) { 
       if (numbers[a.item] > numbers[b.item]) { 
        return 1; 
       } else if (numbers[a.item] < numbers[b.item]) { 
        return -1; 
       } else { 
        // the characters are equal. 
        return 0; 
       } 
      } 
     } 
    }] 
}); 

+0

完美谢谢 – Coppermill