2012-12-31 27 views
3

我试图通过使用此代码来改变的jqGrid的排序顺序的排序顺序:排序图标不更新上设置

jQuery('#id').setGridParam({sortorder:"desc"}).trigger("reloadGrid"); 

它改变了表,但表中的排序图标是不会改变的排序顺序按照订单。在onSortCol我排序实际排序列的列。但是,当我使用上面的一段代码来设置排序顺序时,sortorder被设置,但排序图标仍然显示以前的排序顺序。

_table.jqGrid({ 

     datatype: 'local', // disable initial autoload. this will be when load function is called "json", 
     altRows: true, 
     altclass : 'AltRowClass', 
     gridView: true, 
     width:850, 
     height:"auto", 
     rowheight: 75,   
     align: 'center', 
     treeGrid: false, 
     loadonce:true, 
     ExpandColumn: 'name', 
     loadtext : 'Currently updating', 
     mtype : 'POST', 
     colNames: ['MSISDN','IMSI','Last name','First name','Device type','CE Index','Customer lifetime value'], 
     colModel: [ 
        { name: 'MSISDN', align: 'center', hidden: false, sortable: false,formatter: maskingColumn}, 
        { name: 'IMSI', align: 'center', hidden: false, sortable: false,formatter: maskingColumn}, 
        { name: 'LastName', align: 'center', hidden: false, sortable: false}, 
        { name: 'FirstName', align: 'center', hidden: false, sortable: false}, 
        { name: 'DeviceType', align: 'center', hidden: false, sortable: false,formatter: columnData}, 
        { name: 'CEIndex', align: 'center', hidden: false, sortable: true, sorttype: 'int'}, 
        { name: 'CustomerLifetimeValue', align: 'center', hidden: false, sortable: false} 
        ], 
     sortname: 'CEIndex', 
     sortorder: 'desc', 
     loadComplete: function(data) 
     { 
      var rowCount = _table.jqGrid('getGridParam', 'records'); 

      if (rowCount > 5) { 
       _table.parents("div.ui-jqgrid-bdiv").css({'max-height':'300px'}); 
       _table.closest(".ui-jqgrid-bdiv").css({'overflow-y':'auto'}).css({'overflow-x':'hidden'}); 
      } 
      if (rowCount != 0) { 
       _table.parents().find('.ui-jqgrid-view').first().show(); 
      } 
      if (rowCount <= rowsNum) { 
       utils.find('cei-drill-customer-detail-showmore').hide(); 
      } else { 
       utils.find('cei-drill-customer-detail-showmore').show(); 
      } 
      _table.trigger("reloadGrid"); 
     } , 
     onSortCol: function (data, status, xhr) { 
      if (xhr == 'asc') { 
       var postData = this.p.postData.jsonRequest.replace('Top','Bottom'); 
       actionInputObjectExportCustDrilldown.parameters.requestQuery = actionInputObjectExportCustDrilldown.parameters.requestQuery.replace('Top','Bottom'); 
       var postDataVar = { 
         operation : 'drillDownLevel1', 
         drillLevel1 : "drilldown", 
         jsonRequest : postData 
       }; 
       _this.load(postDataVar); 
      } else if (xhr == 'desc') { 
       var postData = this.p.postData.jsonRequest.replace('Bottom','Top'); 
       actionInputObjectExportCustDrilldown.parameters.requestQuery = actionInputObjectExportCustDrilldown.parameters.requestQuery.replace('Bottom','Top'); 
       var postDataVar = { 
         operation : 'drillDownLevel1', 
         drillLevel1 : "drilldown", 
         jsonRequest : postData 
       }; 
       _this.load(postDataVar); 
      } 
     }, 
     beforeProcessing : function(data, status, xhr) { 
      jQuery('div#jqgh_' + prefix + '-cei-dd-customer-details-table_CustomerLifetimeValue.ui-jqgrid-sortable').text("Customer Lifetime Value(" + filterValuesHl.currency + ")"); 
      if (data.queryError != null || !data.rows || data.rows.length == 0) { 
       utils.find('cei-drill-customer-detail-ExportShowMore').hide(); 
       utils.find('div-for-export-customer').hide(); 
       var noError = utils.find('cei-customerDetails-div').parent().find(".cei-customer-details-dd-no-data"); 
       if (data.queryError != null) { 
        noError.text("Error in portlet: " + data.queryError); 
       } else { 
        noError.html("<strong>No Data Available</strong>"); 
       } 
       noError.show(); 
       return false; 
      } else { 
       utils.find('cei-drill-customer-detail-ExportShowMore').show(); 
       utils.find('div-for-export-customer').show(); 
       utils.find('cei-drill-customer-detail-showmore').show(); 
       //Hiding the columns which has no data in all the rows. 
       hideColumns(data); 
       //Setting CSV Data 
       csvData = data; 
      } 
     }, 
     beforeRequest : function() { 
      _table.parents().find('.ui-jqgrid-view').first().hide(); 
      utils.find('cei-customerDetails-div').parent().find(".cei-customer-details-dd-no-data").hide(); 
     }, 
     loadError : function(xhr, st, err) { 
      utils.find('cei-drill-customer-detail-ExportShowMore').hide(); 
      utils.find('div-for-export-customer').hide(); 
      var noError = utils.find('cei-customerDetails-div').parent().find(".cei-customer-details-dd-no-data"); 
      noError.html("<html>Error connecting portlet: " + err + "</strong>"); 
      noError.show(); 
     } 

    }); 

回答

0

您可以尝试以下代码,其中id是您的列名称。

$('#grid').jqGrid('setGridParam', {sortorder: 'desc'}); $('#grid').jqGrid('sortGrid', 'id');