【发布时间】:2012-02-13 07:08:18
【问题描述】:
回答
how to make sort icons visible in all column headers in jqgrid regardless on sort status
描述如何向列添加可排序指示。
默认排序指示器很难区分已排序和未排序的列。
除了排序指示符之外,如何在已排序的列标题文本下划线?
【问题讨论】:
标签: javascript jqgrid
回答
how to make sort icons visible in all column headers in jqgrid regardless on sort status
描述如何向列添加可排序指示。
默认排序指示器很难区分已排序和未排序的列。
除了排序指示符之外,如何在已排序的列标题文本下划线?
【问题讨论】:
标签: javascript jqgrid
我将演示从之前的答案修改为 the following 现在显示
我在演示中使用了 CSS 类,我在其中添加下划线改变了文本的颜色
.sortedColumnHeader > div { text-decoration: underline; color: blue; }
如果我们向前播放,我们可以只使用“ui-state-highlight”来突出显示(参见another demo)。列标题可能与标准列有太多区别:
对应的代码是
var $grid = $("#list"), colModel, sortName;
// 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();
$(this.grid.headers[this.p.lastsort].el).removeClass('sortedColumnHeader');
}
$(this.grid.headers[idxcol].el).addClass('sortedColumnHeader');
}
});
// show sort icons of all sortable columns
colModel = $grid.jqGrid('getGridParam', 'colModel');
sortName = $grid.jqGrid('getGridParam', 'sortname');
$('#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'});
}
if (cmi.name === sortName) {
$(this).addClass('sortedColumnHeader');
}
});
最后我想再引用一个old answer,它显示了另一种高亮排序列的复杂方法。
【讨论】:
'ui-state-highlight' 而不是'sortedColumnHeader' 的第二个演示的链接是here
$(elem).addClass('ui-state-error') 。在税列中。这样做的目的是什么,我没有看到税收列有什么不同?
$(elem).addClass('ui-state-error') 在the second demo 中的使用在这里没有特殊意义。这只是另一个answer的副本。