Search code examples
attributesconfigtabulator

Basic table configuration for Tabulator


I am new to Tabulator and was trying some things out with the help of the documentation. I am not sure if I understand the functionality of the "Persistent Module" right, but it seems suitable for my desired behaviour: I have an app with three pages. On every page are different tables with different data. I could set them up one by one with the Tabulator options. But some settings should apply to all the tables, e.g. in all tables the second row should have an orange background. Is there some way to set up a basic table configuration (e.g. stored in an extra file, json or something like that) which then I can access in the code and basically setting up all tables with the same "look"? I hope you understand what I mean. Feel free to ask back and thanks in advance!


Solution

  • The persistence module is intended for storing changes made by the user for use next time, for example if they change column sizes the table will look the same when they come back. It is not for sharing setup between tables.

    If you want to ensure that the same setup options are used on all tables on a page, then you can override the default config options using the below code, from that point on any tables that are setup will have that setting. for example if you wanted every table on the page to have the same layout mode, you could add the above code before you create your first table, all tables created after that point would have that layout mode unless you set something differently in its constructor:

    Tabulator.prototype.defaultOptions.layout = "fitColumns";
    

    More details on this can be found in the Default Options documentation

    If you want to persiste consistent styling across tables then i recomend just using CSS.