【问题标题】:how to undeline sorted column header in jqgrid如何在jqgrid中为已排序的列标题加下划线
【发布时间】:2012-02-13 07:08:18
【问题描述】:

回答

how to make sort icons visible in all column headers in jqgrid regardless on sort status

描述如何向列添加可排序指示。

默认排序指示器很难区分已排序和未排序的列。

除了排序指示符之外,如何在已排序的列标题文本下划线?

【问题讨论】:

    标签: javascript jqgrid


    【解决方案1】:

    我将演示从之前的答案修改为 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,它显示了另一种高亮排序列的复杂方法。

    【讨论】:

    • 非常感谢。优秀。答案中的图片显示黄色 bakcground 中的日期列,但在 IE9 中打开的演示链接不会更改日期列背景颜色。演示和答案代码与答案中用于图片的代码不同吗?
    • @Andrus:不客气!使用'ui-state-highlight' 而不是'sortedColumnHeader' 的第二个演示的链接是here
    • 谢谢。新演示还包含 $(elem).addClass('ui-state-error') 。在税列中。这样做的目的是什么,我没有看到税收列有什么不同?
    • @Andrus:$(elem).addClass('ui-state-error')the second demo 中的使用在这里没有特殊意义。这只是另一个answer的副本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 2015-08-08
    • 2018-01-04
    • 2018-08-05
    • 2013-09-23
    • 1970-01-01
    相关资源
    最近更新 更多