2016-11-16 146 views
0

以下是我的代码。我想通过点击表格标题来排序数据。但它不起作用。jqGrid排序不起作用

$("#list_records").jqGrid({ 
        url: 'ajaxFetchTableInfo.php?table=GET_TRAINING_TYPE', 
        editurl: 'ajaxSaveTrainingType.php', 
        datatype: "json", 
        colNames: ["TRAINING TYPE ID", "TRAINING TYPE NAME", "REMARKS"], 
        colModel: [ 
         { 
          label: 'TRAINING_TYPE_ID', 
          name: 'TRAINING_TYPE_ID', 
          index: 'TRAINING_TYPE_ID', 
          editable:true, 
          sortable:true, 
          sorttype: "text", 
          editoptions:{readonly:"readonly"}, 
          width: 75       
         }, 
         { 
          label : 'TRAINING_TYPE_NAME', 
          name: 'TRAINING_TYPE_NAME', 
          index: 'TRAINING_TYPE_NAME', 
          width: 140, 
          editable: true, // must set editable to true if you want to make the field editable 
          editoptions: {size:50, maxlength: 80}, 
          editrules:{required: true, maxlength: 80}, 
          sortable:true, 
          sorttype: "text", 
          // set options related to the layout of the Edit and Add Forms 
          formoptions: { 
           colpos: 1, // the position of the column 
           rowpos: 2, // the position of the row 
           label: "Training Type Name:", // the label to show for each input control 
           elmsuffix: "(*)"     

          } 
         }, 
         { 
          label : 'Remarks', 
          name: 'REMARKS', 
          width: 100, 
          editable: true, 
          edittype: 'textarea', 
          editoptions:{rows:3, cols:45}, 
          formoptions: { 
           colpos: 1, 
           rowpos: 3 
          } 
         } 
        ], 
        loadOnce : true, 
        viewrecords: true, 
        altRows: true, 
        width: 780, 
        height: 200, 
        rowNum: 10, 
        rowList:[10, 20, 30], 
        caption:"Training Type Information", 
        sortname: 'TRAINING_TYPE_ID', 
        sortorder: "asc", 
        emptyrecords: "No Records to Display.", 
        //footerrow: true, 
        pager: "#perpage" 
       }); 
+0

查看这个例子。会帮助你http://trirand.com/blog/jqgrid/jqgrid.html – RJParikh

回答

1

此时应更换loadOnce : trueloadonce : true。服务器应从服务器返回全部数据(所有页面)(url: 'ajaxFetchTableInfo.php?table=GET_TRAINING_TYPE')。

+0

它的工作原理。谢谢。 – Jahirul

+0

当我更换loadOnce时:true to loadonce:true,它正在做排序很好。但是,当我添加一个新行或编辑现有行时,它不会加载更改,直到页面刷新。我能做些什么来排序和更新实时更改? – Jahirul

+0

对于“ajaxFetchTableInfo.php?table = GET_TRAINING_TYPE”,我的代码如下所示:if($ table =='GET_TRAINING_TYPE') $ sql =“SELECT * FROM EL_TRAINING_TYPE”; \t $ rs = exec_sql($ sql); if(!$ rs){ \t \t echo“Failed。Error:”。$ rs; \t} \t else { \t \t echo get_json($ rs); \t} – Jahirul