2012-06-16 40 views
1

的默認排序列圖標,我必須展示在jqGrid的排序列圖標。我在這裏找到答案。我嘗試過,現在我可以在所有可排序的列標題中看到排序圖標,但默認排序列未顯示突出顯示的圖標。需要顯示的jqGrid

這是我的腳本:

var $tempX= $(divId), colModel, sortName; 


    jQuery(divId).jqGrid({ 
     datatype: "local", 
     height: 250, 
     width:1000, 
     colNames:eval(colNamesVal), 
     colModel:eval(colModelVal), 
     rowNum:35, 
     rowList:[35,60,100,1000000000], 
     rownumbers: true, 
     rownumWidth:50, 
     height:"auto", 
     pager: '#pager2', 
     ignoreCase: true, 
     //altRows:true, 
     pagination:true, 
     headertitles:true, 
     sortable:true, 
     sortorder: "asc", 
     viewrecords: true, 
     onSortCol: function (index, idxcol, sortorder) { 
      if (this.p.lastsort >= 0 && this.p.lastsort !== idxcol 
        && this.p.colModel[this.p.lastsort].sortable !== false) { 
       // show the icons of last sorted column 
       $(this.grid.headers[this.p.lastsort].el) 
        .find(">div.ui-jqgrid-sortable>span.s-ico").show(); 
       $(this.grid.headers[this.p.lastsort].el).removeClass('sortedColumnHeader'); 
      } 
      $(this.grid.headers[idxcol].el).addClass('sortedColumnHeader'); 
     }, 
     loadComplete: function(){ 
      $("option[value=1000000000]").text('All'); 
     } 
    }); 

colModel = $tempX.jqGrid('getGridParam', 'colModel'); 
    sortName = $tempX.jqGrid('getGridParam', 'sortname'); 
    $('#gbox_' + $.jgrid.jqID($tempX[0].id) + 
     ' tr.ui-jqgrid-labels th.ui-th-column').each(function (i) { 
     var cmi = colModel[i], colName = cmi.name; 

     if (cmi.sortable !== false) { 
      // show the sorting icons 
      $(this).find('>div.ui-jqgrid-sortable>span.s-ico').show(); 
     } else if (!cmi.sortable && colName !== 'rn' && colName !== 'cb' && colName !== 'subgrid') { 
      // change the mouse cursor on the columns which are non-sortable 
      $(this).find('>div.ui-jqgrid-sortable').css({cursor: 'default'}); 
     } 
     if (cmi.name === sortName) { 
      $(this).addClass('sortedColumnHeader'); 
     } 
    }); 

在這個任何人幫助嗎? 謝謝!

回答

0

你可能指的是以下my old answerThe demothis one這就是你使用的。

你寫你想看到在默認排序列高亮顯示的圖標。爲了解決這個問題,你必須在網格中有sortname選項。定義.sortedColumnHeader > div CSS設置也很重要。如果你在the demo這樣做,那麼一切都按預期工作。

+0

這正是我需要顯示的圖標爲默認排序列。我試過你的劇本。但還是一樣。所有的列都有圖標,但對於排序的列圖標,它們有點鮮豔的顏色,可以是向下箭頭,也可以是向上箭頭,具體取決於排序順序! – user1199537

+0

@ user1199537:沒有默認的排序列,因爲你沒有定義'sortname'選項。如果您使用'data'參數來創建非空網格,則數據將被**排序**。要使用必須使用的排序數據,通過包含'sortname'選項來指定排序所在的列。剛(http://www.ok-soft-gmbh.com/jqGrid/ShowAlwaysSortableIcons1.htm)更加仔細地研究[演示]的代碼。 – Oleg

+0

對於每個網格,我傳遞sortname ...就像這樣:loadGrid(colNames,colModels,jsonObj.result,divId,'name'); – user1199537