按空单元格排序“emptyTo”Tablesorter不起作用

问题描述 投票:1回答:1

我有一个表格,其中包含一些日期数据,我希望它按空白单元格排序。默认情况下,tablesorter将它们放在底部,我需要它们在顶部。我读了其他相关的帖子,似乎没有一个对我有用,我想弄明白为什么。

我正在使用Tablesorter 2.29.5

 /*! TableSorter (FORK) v2.29.5 *//*
  * Client-side table sorting with ease!
  * @requires jQuery v1.2.6+

我正在设置库(其他一切正常)

这是我在Jquery中的tablesorter配置:

 $('#tablesorter')
            .tablesorter({
                theme : 'blue',
                widgets: ['filter', 'reflow','resizable'],
                sortList: [[0,0]],
                emptyTo: 'top',
                widgetOptions: {
                    resizable: true, 
                    resizable_widths : [ '12%', '12%', '10%', '10%', '10%', '10%', '17%', '9%', '9%','0%']   
                }

            }).tablesorterPager({
                container: $(".paginatorTableSorter"),
                output: '{{ "table.showing"|trans }} {startRow} {{ "table.to"|trans }} {endRow} ({filteredRows})'
            });
        $(".tablesorter").data('tablesorter').widgets = ['zebra', 'columns'];
        $(".tablesorter").trigger('applyWidgets');
        $('#tablesorter')
                .trigger('sortReset')
                .trigger('filterReset')
                .trigger('resizableReset')
                .trigger('pageAndSize', [1, 10]);

我也尝试按列排序,但因为它们是日期空单元格被忽略,所以我设置emptyTo:'top'跟随jQuery tablesorter文档https://mottie.github.io/tablesorter/docs/#emptyto

这是我的(改编)html(和Twig):

<thead>
  <tr class="warning">
    <th class="text-center">{{ 'table.title.time.check-in' |trans }}</th>
    <th class="text-center">{{ 'table.title.time.check-out' |trans }}</th>                        
  </tr>
</thead>
<tbody>
  <tr>
    <td class="text-center">{{ line.FECHA_E }}</td>
    <td class="text-center">{{ line.FECHA_S }}</td>
  </tr>
</tbody>

有什么我想念的吗?

jquery tablesorter
1个回答
0
投票

所以,是的。正如莫蒂所说,我仔细检查了输入的实际价值并发现了问题。

<tbody>
 <tr>
  <td class="text-center">{{ line.FECHA_E }}</td>
  <td class="text-center">{% if line.FECHA_S is null %}{% else %}{{ line.FECHA_S }}{% endif %}</td>
 </tr>
</tbody>

在发布问题之后,我意识到我在配置上留下了.trigger('sortReset')但是我的代码被评论了。

如果有人复制我的tablesorter配置,只需删除该部分,这样就不会重置默认的排序值。

再次感谢Mottie!

© www.soinside.com 2019 - 2024. All rights reserved.