Inherit settings from another datatable?

Inherit settings from another datatable?

cojlcojl Posts: 14Questions: 3Answers: 1
edited October 2015 in Free community support

Hello!

I have a simple question regarding creating multiple tables. For instance, I have a table in which I translate some of the oLanguage attributes, as well as specify some other general settings (serverside, savestate etc).

Say I want to create another table using these same settings, is there a way to inherit these from the first table, or do I have to specify them for each table repeatedly?

Example:

 $('#table1').DataTable({
            "responsive": true,
            "serverSide": true,
            // etc..

 $('#table2').DataTable({
            "responsive": true,
            "serverSide": true,
            // etc..

I haven't found anything regarding this in the documentation, but maybe I'm just blind!

To clarify; I know how to instantiate multiple tables, I just want to know how to use the same settings for multiple tables that are processed server-side. I know it's possible clientside, basically you just use the same table with different data on the client.

Thanks for any explanation!

Cheers

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    This is actually a good question... I thought it would be easy with the settings() resource, but I wasnt able to pull it off.. :(

  • cojlcojl Posts: 14Questions: 3Answers: 1

    Yea, I saw this function as well, but it doesn't seem to help in this matter. :/ The problem now is I get a lot of redundant code, since my tables are basically identic except for the columns, which I render in different ways depending on what table it is.

    Does anyone have any suggestion on how to solve this? :)

  • allanallan Posts: 62,313Questions: 1Answers: 10,225 Site admin
    edited October 2015 Answer ✓

    The settings() method should be avoided if possible. It is the internal DataTables settings object - its properties can, will and do change between versions.

    Currently there is no why to inherit from an existing DataTable directly - however you could:

    1. Set defaults
    2. Use a common initialisation object that you $.extend() for each table.

    Allan

  • cojlcojl Posts: 14Questions: 3Answers: 1

    Thank you for your response Allan! I'll go ahead and use defaults.

    Cheers for a great plugin

This discussion has been closed.