2012-05-16 56 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