【问题标题】:tablesorter grouping widget customization表格排序器分组小部件自定义
【发布时间】:2014-01-05 03:29:27
【问题描述】:

我有一个要求,我需要能够根据用户的选择按表中的特定列进行分组。我需要镜像 jqgrid 文档中所示的动态分组功能。我正在使用表格排序器分组机制。最初我尝试了运行良好的 jqGrid,但我们无法根据我们的要求自定义 css。我正在使用 tablesorter 和分组小部件。 现在使用这个组合,我可以看到您只需单击列标题即可按表中的所有列进行分组,我需要对其进行限制。所以,基本上我需要加载带有分组的特定列的表,然后当用户单击其他列时,只应该进行排序。此外,在对小部件进行分组时,只考虑第一个字母而不是整个单词。我检查了分组代码,并且使用了一个拆分功能,应该对其进行修改。谁能指出我实现目标的正确方向

【问题讨论】:

    标签: jquery tablesorter


    【解决方案1】:

    分组小部件允许您将其设置为按字母、单词、分隔符、日期分组并禁用列分组 - 请参阅“标题类名称”部分以了解可以使用的 full list class names

    在您的情况下,在要按单词分组的列上使用 group-word 类名,并使用 group-false 禁用分组 (demo)

    HTML

    <table class="tablesorter">
        <thead>
            <tr>
                <th class="group-word">AlphaNumeric</th>
                <th class="group-false">Numeric</th>
                <th class="group-false">Animals</th>
                <th class="group-false">Sites</th>
            </tr>
        </thead>
        <tbody>
            ...
        </tbody>
    </table>
    

    脚本

    $('table').tablesorter({
        theme: 'blue',
        sortList: [ [0, 0] ],
        widgets: ['zebra', 'group']
    });
    

    CSS(可折叠箭头)

    /* collapsed arrow */
     tr.group-header td i {
        display: inline-block;
        width: 0;
        height: 0;
        border-top: 4px solid transparent;
        border-bottom: 4px solid #888;
        border-right: 4px solid #888;
        border-left: 4px solid transparent;
        margin-right: 7px;
        user-select: none;
        -moz-user-select: none;
    }
    tr.group-header.collapsed td i {
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-left: 5px solid #888;
        border-right: 0;
        margin-right: 10px;
    }
    

    【讨论】:

    • 首先感谢您的及时回复。最初,我将参数 sortList: [ [1, 1] ] 传递给基于运行良好的第二列的分组。然后我按照建议添加了组标题,并且效果很好。我面临的唯一问题是,当我单击其他列标题时,初始分组被删除。我知道如果您按 SHIFT 然后单击列标题,它将在分组中排序。我可以编写/修改任何 jquery 以便无需按 SHIFT 键即可实现此行为。
    • 我不确定这是否是您想要的,但请尝试使用 sortForce option 始终先对所需的列进行排序 (demo)
    • 是的,这正是我想要的…… sortforce 选项成功了。非常感谢... !!!!我现在唯一要做的就是更改展开和收缩按钮。
    • 这一切都是用css完成的!组标题中有一个&lt;i&gt;&lt;/i&gt; 元素,其样式为:&lt;tr class="group-header"&gt;&lt;td colspan="4"&gt;&lt;i&gt;&lt;/i&gt;&lt;span class="group-name"&gt;abc&lt;/span&gt;&lt;span class="group-count"&gt; (#)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;。当组折叠时,collapsed 类名称将添加到 group-header。我在答案中添加了特定的 css。
    • 是的,我明白了……我遇到的一个问题是我想将分组行的 colspan 增加 1 。那么,有什么方法可以实现这一点。
    猜你喜欢
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多