2012-05-16 58 views
1

不知道是否我錯過了一個選項,但我無法使用以下代碼對jqGrid進行排序。我的網格剛好有一列,我想使排序:jqGrid:排序不工作,在colmodel中指定索引,排序,排序類型

$('#jqgrid').jqGrid({ 
        url: contextPath + '/js/jqgrid-data.json', 
        datatype: 'json', 
        colNames: ['Destination Name'], 
        colModel: [ 
         { name: 'DestName', 
          sortable: true, 
          sorttype: 'text', 
          index: 'DestName' 
         } 
        ], 
        sortname: 'DestName', 
        sortorder: 'asc', 
        jsonReader: { repeatitems: false }, 
        height: 'auto', 
        width: 600, 
        onSelectRow: function(id){ 
         alert('Selected row ID ' + id); 
        } 
       }); 

的數據從服務器看起來是這樣的:

{ 
    "total": 1, 
    "page": 1, 
    "records": 10, 
    "rows": [ 
     { 
      "id": "1", 
      "DestName": "Administration Office" 
     }, 
     { 
      "id": "2", 
      "DestName": "Business Office" 
     } 
.... 
} 

想法?

+0

如果您想在未來收到有關您的問題的答案,您應該開始[「接受」](http://meta.stackexchange.com/a/5235/147495)答案。此外,您有權每天投票30次有用的答案或問題**(請參閱[此處](http://meta.stackexchange.com/a/5213/147495))。投票不僅提供其他聲望點。它可以幫助其他訪問者找到有用的答案。所以如果你想幫助別人,請使用你的權利並使用投票。我建議您閱讀(重新閱讀)FAQ的[部分](http://stackoverflow.com/faq#howtoask)。 – Oleg

回答

0

服務器負責排序,而不是jqgrid。選項指定給jqgrid,以便它將正確的參數傳遞給服務器。所以你應該在服務器端捕獲sordsidx params(用於排序方向和排序字段),然後在那裏排序。

+0

我發現這個Stackoverflow鏈接也很有用:[jqGrid排序討論](http://stackoverflow.com/questions/2756521/jqgrid-formatter-and-sortable-column-doesnt-sort) – Ramya