Individual Column Filtering - Show 'All' in drop down and add Label before dropdown

Individual Column Filtering - Show 'All' in drop down and add Label before dropdown

vshakevshake Posts: 2Questions: 2Answers: 0
edited August 2016 in Free community support

Hi,

I'm using the following code to add filtering on one column in my datatable:

   "initComplete": function () {
                    this.api().column(4).every( function () {
                        var column = this;
                        var select = jQuery('<select><option value=""></option></select>')
                        .appendTo( jQuery(column.header()).empty() )
                        .on( 'change', function () {
                            var val = jQuery.fn.dataTable.util.escapeRegex(
                                jQuery(this).val()
                            );

                            column
                                .search( val ? '^'+val+'$' : '', true, false )
                                .draw();
                        });

                        column.data().unique().sort().each( function ( d, j ) {
                            select.append( '<option value="'+d+'">'+d+'</option>' )
                        });
                    });
                }   

I was wondering 1) if there is a way to add an 'All' option to the filter rather than just the blank filter selection option and 2) if there is a way to add a label to the left of the filter dropdown, e.g., Type?

Thanks!

Answers

  • peterstilgoepeterstilgoe Posts: 22Questions: 6Answers: 0

    var select = $('<select><option value="">ALL</option></select>')

This discussion has been closed.