How can we set default columns/columndefs to reuse across all tables

How can we set default columns/columndefs to reuse across all tables

setwebmastersetwebmaster Posts: 78Questions: 5Answers: 0

As the title says, I'm trying to set default columns to reuse across all my tables as they all share common control columns with plugins/extensions.

For example, my first column is always for the "responsive" plugin, my second columns would be for the checkboxes and my third one would be for CRUD action buttons which are rendered in columnDefs.

Any help would be really appreciated, thanks in advance!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    You can set defaults for all columns, but there isn't a built in way to define a group of columns (i.e. column 1 should have a title of x and column 2 should have a title of y).

    However, it is fairly easy to do with $.extend():

    var columns = [
      { title: 'x' },
      { title: 'y' }
    ];
    
    $('#example').DataTable( {
      columns: $.extend( true, columns, [
         { title: 'xx' },
         null
       ] )
    } );
    

    Allan

  • setwebmastersetwebmaster Posts: 78Questions: 5Answers: 0

    Wow sorry for not coming back and thank you for your help. I ended up finding the answer to my problem in your great documentation (there's a lot so it was easy to get lost but there is a ton of great info!)

This discussion has been closed.