Plug-in example for options?

Plug-in example for options?

Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10

I've made a couple of plug-ins for the api, but is there an example of a plug-in to add options?

I have several tables that are "static" in the sense that I want to show the table without the user having the ability to interact with the table.

For those tables I end up repeating this since the defaults for these are true:

{
    ....
    info: false,
    ordering: false,
    paging: false,
    searching: false,
    ....
}

It would be nice if I could simply enter this:

{
    ....
    static: true,
    ....
}

and then have DataTables set info, ordering, paging, and searching to false before the table is initialized.

Is there anything I could be pointed to that would help me start?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Sounds like you want to set default options.

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10

    Thanks, Kevin (@kthorngren), that's one option, but I only want to make about a third of my tables "static" so I'd be back to the same issue of setting those options for the other tables.

    I'm sure there's a way to approach it the way I'm thinking, but I just don't see an example.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited February 17 Answer ✓

    You could combine two configuration objects together, something like this:

    var staticOptions = {
        info: false,
        ordering: false,
        paging: false,
        searching: false,
    };
    
    var tableOptions = {
      select: true
    };
    
    var table = new DataTable('#example', 
      $.extend( staticOptions, tableOptions )
    );
    

    https://live.datatables.net/kotudavi/1/edit

    Or you can do something like this;

    var staticOptions = {
        info: false,
        ordering: false,
        paging: false,
        searching: false,
    };
    
    
    var table = new DataTable('#example', 
      {
        ...staticOptions,
        select: true
      }
    );
    

    https://live.datatables.net/qukogezu/1/edit

    Its more a. Javascript exercise than Datatables. You just need to find your favorite way to combine two Javascript objects.

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10

    Oooh -- I like that second option!

    I was trying something like that before but was leaving out the ... part and it obviously wouldn't work!

    As always, thanks Kevin!

Sign In or Register to comment.