为什么每次单击列标题时都无法在jqgrid中对网格进行排序? [英] Why is it that I cannot sort my grid in jqgrid everytime I clicked the column header?

查看:274
本文介绍了为什么每次单击列标题时都无法在jqgrid中对网格进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很困惑,每次单击列标题时,使用jqgrid的程序都不会排序(降序)?我尝试创建一个使用本地数据(.json数据)的程序,当我单击列标题时,它在排序时效果很好.那么第一个是什么问题呢?我正在使用来自客户端服务器的数据....

I was really confused that my program using jqgrid won't sort (descending) everytime I clicked the column header? I tried creating a program where I use local data (.json data) and it work great in sorting when I clicked the column header. So what's the problem with the first one? I am using the data from client server....

这是我的JavaScript代码:

Here's my javascript code:

  $("#btnQueryMainAccountGroups").click( function() {
    var params = {
      "SessionID": $("#eSessionID3").val(),
      "dataType": "data"
    }
    $('#tblData').setGridParam({
      url:'process.php?path=' + encodeURI('masterData/data') + '&json=' + encodeURI(JSON.stringify(params)), 
      datatype: olSettings.ajaxDataType,  
    });
    $('#tblData').trigger('reloadGrid');
    }); 

    $("#tblData").jqGrid({
    url: '',
    datatype: '',
    jsonReader : {
      root: function(obj) {
        var root = [];

    if  ('error' in obj) 
    {
      showMessage(obj.error['class'] + ' error: ' + obj['error']['msg']);
    }
    else
    {
      $.each(obj['result']['main']['rowdata'], function(rowIndex, rowDataValue) {
        var row = {};
        $.each(rowDataValue, function(columnIndex, rowArrayValue) {
          var fldName = obj['result']['main']['metadata']['fields'][columnIndex].name;
          row[fldName] = rowArrayValue;                
        });
        root[rowIndex] = row;
      });
    };
    return root;
  },
  page: "result.main.page",
  total: "result.main.pageCount",
  records: "result.main.rows",
  repeatitems: false,
  id: "0"
},
serializeGridData: function(postData) {
  var jsonParams = {
    'SessionID': $('#eSessionID3').val(),
    'dataType': 'data',
    'recordLimit': postData.rows,
    'recordOffset': postData.rows * (postData.page - 1),
    'rowDataAsObjects': false,
    'queryRowCount': true,
    'sort_fields': postData.sidx
  };

  return 'json=' + JSON.stringify(jsonParams);
},

},
colNames:['ID','Code', 'Description','Type'],
colModel:[
  {name:'group_id'},
  {name:'group_code',align:'center',width:100},
  {name:'group_desc'},
  {name:'type'}
],

viewrecords: true,
rowList:[5,10,50,100],
pager: '#tblDataPager',
sortname: 'group_desc',
sortorder: 'asc',
rowNum:5,
loadonce:false,
caption: "MainGroup"
});

$("#tblData").setGridWidth($(window).width() - 70);
$("#tblData").jqGrid('sortableRows');

这是我在javascript中无法对jqgrid进行排序的代码... 我的process.php代码:

that's my code in javascript where i can't sort my jqgrid... my process.php code:

 <?php 
     print(file_get_contents("http://localhost/" .... "?json=" . $_GET["json"]));
 ?>

将数据加载到jqgrid中没有问题.唯一的问题是我无法按降序对其进行排序.每次单击列标题时,它只会按升序排序,如果再次单击,则不会发生降序.有什么问题吗?

There's no problem in loading of data to the jqgrid. The only problem is that I cannot sort them in descending order. Everytime i clicked a column header, it only sorts ascending, and if i clicked again, no descending happen. What's the problem?

推荐答案

您应在必填字段的colModel中使用 sortable:true ,如下所示:

You should use sortable: true in your required fields' colModel as follows:

colModel:[
 {name:'group_id', sortable: true},
 {name:'group_code',align:'center',width:100, sortable: true},
 {name:'group_desc', sortable: true},
 {name:'type', sortable: true}
],

您现在应该可以正确排序了.

You should now able to sort properly.

这篇关于为什么每次单击列标题时都无法在jqgrid中对网格进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆