簡體   English   中英

Datatables篩選器中的columnfilterwidget排序問題

[英]columnfilterwidget in Datatables Filter sort issue

我正在將DataTables 1.10和Columnfilterwidget一起使用,

我面臨的問題是我的值像0,1.44,10,100,100.00,20,20.13

現在,Columnfilterwidget正在按字母順序對這些值進行排序

0
1.44
10
100
100.00
20
20.13

但是我希望它們被數字過濾

0
1.44
10
20
20.13
100
100.00

像這樣,

這是我到目前為止嘗試過的

在Columnfilterwidget.js文件中

          ColumnFilterWidget.prototype.fnDraw = function() {
                    var widget = this;
                    var oDistinctOptions = {};
                    var aDistinctOptions = [];
                    var aData;
                    if ( widget.asFilters.length === 0 ) {
                            // Find distinct column values
                            aData = widget.oDataTable.fnGetColumnData( widget.iColumn );

                            $.each( aData, function( i, sValue ) {
                                    var asValues = widget.sSeparator ? sValue.split( new RegExp( widget.sSeparator ) ) : [ sValue ];
                                    $.each( asValues, function( j, sOption ) {
                                            if ( !oDistinctOptions.hasOwnProperty( sOption ) ) {
                                                    oDistinctOptions[sOption] = true;
                                                    aDistinctOptions.push( sOption );
                                            }
                                    } );
                            } );
                            // Build the menu
                            widget.$Select.empty().append( $( '<option></option>' ).attr( 'value', '' ).text( widget.oColumn.sTitle ) );
//                             aDistinctOptions.sort();
                          aDistinctOptions.sort(function(a,b){return a - b});

                            $.each( aDistinctOptions, function( i, sOption ) {
                                    var sText;
                                    if(sOption==='')
                                            sText = $( '<div> (Blank )</div>' ).text();
                                    else
                                            sText = $( '<div>' + sOption + '</div>' ).text();
                                    widget.$Select.append( $( '<option></option>' ).attr( 'value', sOption ).text( sText ) );
                            } );
                            if ( aDistinctOptions.length > 1 ) {
                                    // Enable the menu
                                    widget.$Select.attr( 'disabled', false );
                            } else {
                                    // One option is not a useful menu, disable it
                                    widget.$Select.attr( 'disabled', true );
                            }
                    }
            };

我將排序功能更改為數字,但是如何識別即將到來的值是數字,我還檢查了sValue值是否為字符串,所以有什么方法可以定義要數字化的列。

還嘗試設置選項oColumnFilterWidgets仍然沒有用。

oColumnFilterWidgets: {
        "aiExclude": [ 0, 1, 10 ],

      "aoColumnDefs": [

//                     { "bSort": false, "sSeparator": " / ", "aiTargets": [ 5 ] },

                    { "fnSort": function( a, b ) { return a-b; }, "aiTargets": [6] },

      {"sType": "numeric", "aiTargets":[6]}
                  ]

        },

我在這里做錯了什么?

感謝Cyber​​hobo修復了此問題。

[ https://github.com/cyberhobo/ColumnFilterWidgets/commit/01efef439c557154bad3d61aa00d47285b6d21d6#diff-72250e81389e20ff2fa22ff884fcb6aaR309][1]

剛做了他在插件中突出顯示的更改

               "oColumnFilterWidgets": {

                  "aoColumnDefs": [

                     { "bSort": false, "sSeparator": " / ", "aiTargets": [ 2 ] },

                     { "fnSort": function( a, b ) { return a-b; }, "aiTargets": [ 3 ] }

                  ]

               }

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM