我觉得这个想法很好,所以我创建the demo它实现了行为:
![enter image description here](https://i.stack.imgur.com/kF2gg.png)
的代码实现这一点:
var $grid = $("#list"), colModel;
// create the grid
$grid.jqGrid({
// all typical jqGrid parameters
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();
}
}
});
// show sort icons of all sortable columns
colModel = $grid.jqGrid('getGridParam', 'colModel');
$('#gbox_' + $.jgrid.jqID($grid[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'});
}
});
修订:如果你需要在大多数栏目中显示信息,你可以进行一些自定义在列标题的CSS中。例如,默认情况下,您在所有列标题中都有“中心”对齐。关于以下CSS
.ui-jqgrid .ui-jqgrid-htable th.ui-th-column
{
text-align:left
}
.ui-jqgrid .ui-jqgrid-htable th.ui-th-column div.ui-jqgrid-sortable
{
margin-left:3px;margin-top:3px
}
您可以将其更改为左对齐。作为结果,你将有列标题的更紧凑的外观:
![enter image description here](https://i.stack.imgur.com/tIC4R.png)
看到相应的demo。顺便说一句,我建议你测试列的宽度是否足够大,以显示在WebKit浏览器的图标进行排序(谷歌Chrome或Safari)。
当然,这应该是答案?! – Whelkaholism 2013-11-20 14:24:19
@Whelkaholism:是的,作品完美!在这里寻找参数描述:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options – 2014-01-10 08:48:17