How do I choose default selections for each column when using select inputs?

How do I choose default selections for each column when using select inputs?

dsmithTekdsmithTek Posts: 2Questions: 2Answers: 0

I have several columns in my datatable header that use the Individual column searching (select inputs) code from the API. Is it possible to choose a separate default option for each column when the page loads? For example, if the choices in column 1 are A and B, I only want As to display initially unless the user selects B.

Here is my code:

initComplete: function () {
                    this.api().columns([3,4,5,6,14,15,16]).every( function () {
                        var column = this;
                        var select = $('<select><option value=""></option></select>')
                            .appendTo( $(column.header()).empty() )
                            .on( 'change', function () {
                                var val = $.fn.dataTable.util.escapeRegex(
                                    $(this).val()
                                );

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

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

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.