2013-01-10 52 views
3

我有劍道UI電網和它始終爲0。劍道UI電網總是從第0頁

開始。如果我更改了排序的列然後將其變爲1並顯示其他頁碼。

我在做什麼錯?

這裏是我的代碼:

$('#userGrid').kendoGrid({ 
       dataSource: { 
        pageSize: 5, 
        transport: { 
         read: { 
          url: ROOT+"user/user-list", 
         }, 
         update: { 
          url: ROOT+"user/update-user", 
          dataType: "POST" 
         } 
        }, 
        error: function(e) { 
         alert(e.responseText); 
        }, 
        schema: { 
         data: "data", 
         model: { 
          id: 'id', 
          fields: { 
           username: {type: "string", editable: false}, 
           type: { 
            type: "number", 
            editable: true, 
            validation: {required: true} 
           }, 
           level: { 
            type: "number", 
            editable: true, 
            validation: {required: true} 
           }, 
           firstName: {type: "string", editable: true}, 
           middleName: {type: "string", editable: true}, 
           lastName: {type: "string", editable: true}, 
           DoB: {type: "date", editable: true}, 
           dateStarted: {type: "date", editable: false}, 
           enabled: { 
            type: "number", 
            editable: true, 
            validation: {required: true} 
           }, 
          } 
         } 
        } 
       }, 
       toolbar: ["save", "cancel"], 
       sortable: true, 
       pageable: { 
        refresh: true, 
        pageSizes: false 
       }, 
       editable:true, 
       columns: 
       [ 
        { 
        field: "username", 
        width: 90, 
        title: "Username" 
        }, 
        { 
        field: "type", 
        width: 50, 
        title: "Type" 
        }, 
        { 
        field: "level", 
        width: 25, 
        title: "Level" 
        }, 
        { 
        field: "firstName", 
        width: 50, 
        title: "First name" 
        }, 
        { 
        field: "middleName", 
        width: 50, 
        title: "Middle name" 
        }, 
        { 
        field: "lastName", 
        width: 50, 
        title: "Last name" 
        }, 
        { 
        field: "DoB", 
        width: 40, 
        title: "DoB", 
        template: '#= kendo.toString(DoB,"dd/MM/yyyy") #' 
        }, 
        { 
        field: "dateStarted", 
        width: 40, 
        title: "Started", 
        template: '#= kendo.toString(dateStarted,"dd/MM/yyyy") #' 
        }, 
        { 
        field: "enabled", 
        width: 40, 
        title: "Enabled" 
        } 
       ] 
      }) 
     }) 
    } 
) ; 
}) 

{"data":[{"id":"1","username":"[email protected]","type":"1","level":"12","firstName":"Tom","middleName":"C","lastName":"Higgins","DoB":"0000-00-00","dateStarted":"0000-00-00","enabled":"0"},{"id":"36","username":"[email protected]","type":"4","level":"12","firstName":"Liam","middleName":"","lastName":"Spelman","DoB":"0000-00-00","dateStarted":"0000-00-00","enabled":"0"},{"id":"56","username":"[email protected]","type":"4","level":"1","firstName":"asdf","middleName":"","lastName":"asdf","DoB":"1970-01-01","dateStarted":"0000-00-00","enabled":"0"},{"id":"57","username":"[email protected]","type":"4","level":"1","firstName":"asdf","middleName":"","lastName":"asdf","DoB":"1970-01-01","dateStarted":"0000-00-00","enabled":"0"}], "rowcount": 4} 

回答

9

是服務器返回total數量的記錄?

如果是,定義schema爲(假設total_size是服務器正在返回的記錄的總數):

schema : { 
    data: "data", 
    total: "total_size", 
    model: { 
     ... 
    } 
} 

如果沒有,嘗試添加到您的schema一個total功能得到它從data數組的大小:

schema : { 
    data: "data", 
    total: function(data) { 
     return data.data.length; 
    }, 
    model: { 
     ... 
    } 
} 
+0

謝謝,有固定的頁碼的問題,但我忘了提,我也有「南 - NaN的4項」,我怎麼解決這個問題呢? (它顯示了當你對列進行排序時它應該如何) – imperium2335

+0

嗯!它應該已經固定了!如果你點擊網格刷新按鈕,它會被修復嗎?接收的數據是怎樣的? – OnaBai

+0

我編輯了一個從服務器返回的數據示例。 Kendo UI網格文檔留下了許多不足之處! – imperium2335