Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82815

Isolate columns

$
0
0

I am working on a rather simple table, it's all HTML really and basic functions like sorting.

I have multiple columns and have set dropdowns to two of them however, they retain the sorting function and I have no idea how to isolate them or alternatively, how to target the rest of the columns in order to make them sortable.

Link to JSfiddle in case it's easier to work with: https://jsfiddle.net/c3tn0ae7/

<script type="text/javascript">
        $(document).ready(function() {
            $('#example').DataTable( {
                initComplete: function () {
                    this.api().columns([5, 11]).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>' )
                        } );
                        
                    } );
                }
            } );
        } );
    </script>

Viewing all articles
Browse latest Browse all 82815

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>