Common Settings for Multiple DataTables

Common Settings for Multiple DataTables

Khushi2005Khushi2005 Posts: 6Questions: 2Answers: 0

Hi,
I am having multiple default settings for various pages. I wanted to have common functions which can be called on tables.

'''
$.extend( true, $.fn.dataTable.defaults, {

"searching"String: false,

"ordering"String: false

} );

$(document).ready(function() {

$('#example'String).DataTable();

} );
'''

Is it possible pass String or call function when you say

$('#example'String).DataTable(call function/string );

Thanks in advance

Answers

  • allanallan Posts: 61,755Questions: 1Answers: 10,111 Site admin

    I don't really understand your question I'm afraid. If you want to apply common settings, you would do so using the defaults, which you mention.

    Allan

  • Khushi2005Khushi2005 Posts: 6Questions: 2Answers: 0

    Let's say I have 6 tables and I am attaching similar styles to 3 tables and other styles to remaining.
    So instead of writing same code , I wanted to check if I can pass String like

                  responsive: true
                , 'bAutoWidth' : false
                ,searching : true
    

    and other styles as
    responsive: true
    , 'bAutoWidth' : false
    ,searching : false
    ,paging : true

    Similar to using this function
    $.extend( true, $.fn.dataTable.defaults, {}

    but instead of fn.dataTable.defaults pass fn.dataTable.(cssClass name or some Selector)

    I hope I am able to explain.

    What I want to accomplish to avoid rewriting all the default formats for different sets.
    The more I am using Datatable more I am enjoying using it.

    Thanks for such an awesome plugIn

  • allanallan Posts: 61,755Questions: 1Answers: 10,111 Site admin

    You could do this:

    var defaults1 = {
      responsive: true,
      ...
    };
    
    var defaults2 = {
      ...
    };
    
    $('#myTable').DataTable( $.extend( true, {}, {
      ...
    }, defaults1 );
    

    Allan

This discussion has been closed.