2014-07-01 58 views
16

嘗試從本地數據源設置我的kendo UI網格上的默認排序列。我讀過遍,我應該把:Kendo UI網格本地數據源列默認排序

sort: { field: "price", dir: "desc" } 

到數據源。我試過這個,但它仍然不起作用(參見下面的例子)。

這裏是我的代碼完整,我哪裏錯了?

$('#grid').kendoGrid({ 
       dataSource: [ 
        { 
         date: "Feb 13 2014", 
         price: 5, 
        }, 
        { 
         date: "Feb 15 2014", 
         price: 7, 
        }, 
        { 
         date: "Feb 12 2014", 
         price: 6, 
        } 
       ], 
       height:500, 
       sortable: true, 
       pageable: false, 
       columns: [ 
        { 
         field: "date", 
         title: "Date" 
        }, 
        { 
         field: "price", 
         title: "Price", 
        } 
       ], 
       sort: {field: "price", dir: "desc"} 
      }); 

回答

35

您正在定義錯誤位置的sort行。你把它作爲一個網格的屬性,但它是(如你所說)的一個數據源的屬性。

把它作爲DataSource屬性的子:

$('#grid').kendoGrid({ 
    dataSource: { 
     data: [{ 
      date: "Feb 13 2014", 
      price: 5, 
     }, { 
      date: "Feb 15 2014", 
      price: 7, 
     }, { 
      date: "Feb 12 2014", 
      price: 6, 
     }], 
     sort: { 
      field: "price", 
      dir: "desc" 
     } 
    }, 
    height: 500, 
    sortable: true, 
    pageable: false, 
    columns: [{ 
     field: "date", 
     title: "Date" 
    }, { 
     field: "price", 
     title: "Price", 
    }], 
}); 

如果還是不行,我可以提供的jsfiddle爲您的工作與周圍。