2012-06-16 37 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