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

Default columnDefs Behavior

$
0
0

Currently on DataTables 2.03. In our base JavaScript, we update the defaults like this:

$.extend( $.fn.dataTable.defaults, {
            autoWidth: true,
            columnDefs: [
                { className: 'text-start', targets: [ 'text-start' ] },
                { className: 'text-center', targets: [ 'text-center' ] },
                { className: 'text-end', targets: [ 'text-end' ] },
                { width: '50px', targets: [ 'width-50'] },
                { width: '100px', targets: [ 'width-100' ] },
                { width: '150px', targets: [ 'width-150' ] },
                { width: '200px', targets: [ 'width-200' ] },
                { width: '250px', targets: [ 'width-250' ] },
                { width: '300px', targets: [ 'width-300' ] },
                { orderable: false, targets: [ 'no-sort' ] },
            ],
            pagingType: 'simple_numbers',
            processing: true,
            responsive: false,
            searchHighlight: true,
            language: {
                paginate: {
                    first: 'First',
                    last: 'Last',
                    next: 'Next',
                    previous: 'Previous'
                },
                search: 'Filter Table:',
            }
        });

This lets us set up various column stylings that we use regularly across the many DataTables in our app.

My question though is if we have a table where we need to add something unique, such as this:

    $('#data-list').DataTable({
        columnDefs: [
            { width: "175px", targets: [ 4,5 ] },
        ],
        order: [ [5, 'desc'], [1, 'asc'] ],
        drawCallback: toggleDataTableControls
    });

Will the defaults be combined with the new ones, or will only the new ones apply? If only the new ones apply, is there an easy way to pull in the defaults to avoid duplicating the options?


Viewing all articles
Browse latest Browse all 82434

Trending Articles



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