2016-11-16 371 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