我覺得這個想法很好,所以我創建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