jQuery Datatables and ColumnFilterWidget integration issue

Posted by user3520135 on Stack Overflow See other posts from Stack Overflow or by user3520135
Published on 2014-05-29T09:07:14Z Indexed on 2014/05/29 9:26 UTC
Read the original article Hit count: 495

Filed under:
|
|
|
|

I am trying to Place the ColumnFilterWidget plugin in the Header of the Datatables Table.

Here are the changes i made in it :

        /**
        * Menu-based filter widgets based on distinct column values for a table.
        *
        * @class ColumnFilterWidgets
        * @constructor
        * @param {object} oDataTableSettings Settings for the target table.
        */
        var ColumnFilterWidgets = function( oDataTableSettings ) {
                var me = this;
                var sExcludeList = '';
//              me.$WidgetContainer = $( '<div class="column-filter-widgets"></div>' );
                me.$WidgetContainer = $( '<tr class="head"></tr>' );
                me.$MenuContainer = me.$WidgetContainer;
                me.$TermContainer = null;
                me.aoWidgets = [];
                me.sSeparator = '';
                if ( 'oColumnFilterWidgets' in oDataTableSettings.oInit ) {
                        if ( 'aiExclude' in oDataTableSettings.oInit.oColumnFilterWidgets ) {
                                sExcludeList = '|' + oDataTableSettings.oInit.oColumnFilterWidgets.aiExclude.join( '|' ) + '|';
                        }
                        if ( 'bGroupTerms' in oDataTableSettings.oInit.oColumnFilterWidgets && oDataTableSettings.oInit.oColumnFilterWidgets.bGroupTerms ) {
                                me.$MenuContainer = $( '<div class="column-filter-widget-menus"></div>' );
                                me.$TermContainer = $( '<div class="column-filter-widget-selected-terms"></div>' ).hide();
                        }
                }

                // Add a widget for each visible and filtered column
                $.each( oDataTableSettings.aoColumns, function ( i, oColumn ) {
                        var $columnTh = $( oColumn.nTh );
                        var $WidgetElem = $( '<th><div class="column-filter-widget"></div></th>' );
                        if ( oColumn.bVisible && sExcludeList.indexOf( '|' + i + '|' ) < 0 ) {
                                me.aoWidgets.push( new ColumnFilterWidget( $WidgetElem, oDataTableSettings, i, me ) );
                        }
                        me.$MenuContainer.append( $WidgetElem );
                } );
                if ( me.$TermContainer ) {
                        me.$WidgetContainer.append( me.$MenuContainer );
                        me.$WidgetContainer.append( me.$TermContainer );
                }
                oDataTableSettings.aoDrawCallback.push( {
                        name: 'ColumnFilterWidgets',
                        fn: function() {
                                $.each( me.aoWidgets, function( i, oWidget ) {
                                        oWidget.fnDraw();
                                } );
                        }
                } );

                return me;
        };

I added a extra <tr class='head'> inside the Datatable, and later on i am trying to append the Filters to that with attached to them,But instead of that it is creating new TR tag and then appending the filters in it.

I even changed my dom of data tables to : dom: '<"clear">Cf<"clear">ltWrip', So the table elements should be there so that it can insert filters inside the head.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery