1

それで、私の質問はタイトルにあります。私はこのデータを持つテーブルを持っています:

9
6
5
'-'
5
2.3
987
'-'
'-'
54.2
41
52
66
55

注: 読みやすくするために、ダッシュを簡単な引用符で囲みます。テーブルソーターを使用すると、すべて正常に動作しますが、ダッシュが上にあり、番号が昇順または逆にソートされます。

または、asc または desc の並べ替えに関係なく、ダッシュをテーブルの一番下に置いておきたい..

それは私の単純な js です:

 $("#table_conso_visu").tablesorter({
        widgets        : ['zebra', 'columns'],
        usNumberFormat : false,
        sortReset      : true,
        sortRestart    : true,
               })

ご協力ありがとうございました。

4

2 に答える 2

0

問題を解決する方法を見つけました。最小値を返すフィルターを作成します。したがって、並べ替えが昇順の場合はダッシュが下に表示され、並べ替えが降順の場合は上に表示されます。私のソートがdescの場合、ダッシュが一番上にある方が論理的だと思います。なぜなら、0を入れた場合と同じだからです;)

だからそれは私のフィルターです:

$.tablesorter.addParser({
            id: "dashSorter",
            format: function(s) {
              return ($.trim(s) === '-') ? Number.MIN_VALUE : $.tablesorter.formatFloat(s.replace(/[,:]/g, ""));
            },
            type: "numeric"
          });

私は正規表現に「:」を入れました.HH:mm:ssの形式で時間があり(削除できます)、私のスクリプトは私のテーブルをソートします:

$("table[name=table_sorter]").tablesorter({

        // initialize zebra striping and filter widgets
        widgets :  ['zebra', 'filter'],
        headers : {
            1 : {sorter:'dashSorter'},
            2 : {sorter:'dashSorter'},
            3 : {sorter:'dashSorter'}
        },
        widgetOptions : {
            // css class applied to the table row containing the filters & the inputs within that row
            filter_cssFilter   : 'tablesorter-filter',

            // If there are child rows in the table (rows with class name from "cssChildRow" option)
            // and this option is true and a match is found anywhere in the child row, then it will make that row
            // visible; default is false
            filter_childRows   : false,

            // if true, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately
            // below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus
            filter_hideFilters : false,

            // Set this option to false to make the searches case sensitive
            filter_ignoreCase  : true,

            // jQuery selector string of an element used to reset the filters
            filter_reset : '.reset',

            // Delay in milliseconds before the filter widget starts searching; This option prevents searching for
            // every character while typing and should make searching large tables faster.
            filter_searchDelay : 300,

            // Set this option to true to use the filter to find text from the start of the column
            // So typing in "a" will find "albert" but not "frank", both have a's; default is false
            filter_startsWith  : false
        }
    });

人々を助けて、すぐにお会いできることを願っています;)

于 2013-09-19T12:15:48.177 に答える