Custom classes for specific instances of the table

Custom classes for specific instances of the table

kaukaskaukas Posts: 4Questions: 0Answers: 0
edited May 2011 in General
Hello, Allan.

Thank you for the great DataTables project!

One question that I have but did not find an obvious solution or explanation in the forums is this - I need to set custom classes (particularly, add a custom class to .dataTables_wrapper) to the generated table. Requirements:
- the custom class is needed only for some of the datatables on the page therefore I don't know how I could override $.fn.dataTableExt.oJUIClasses without affecting other tables (yes, I use jQueryUI styling in all of them),
- the class needs to be applied *before* the table is rendered, particularly before the column widths are calculated because they depend on the custom classes.

I do not want to fire an extra fnAdjustColumnSizing just because I add another class - the table is already quite heavy to render, one extra render request would make it even slower.

I have seen (but can't find where) an idea to swap the dataTableExt object when creating a table and it sounds very hacky to me but I'll go with it before I get any other ideas.

Is there any reason classnames can not be given as initialisation parameters?

Thank you for any feedback or ideas!

Linas

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    edited May 2011
    Currently you can't do this on a per table basis using the methods DataTables provides. However, you can easily do it with just regular DOM or jQuery methods. $().addClass() etc on the element you want to manipulate for example.

    > Is there any reason classnames can not be given as initialisation parameters?

    Yes two reasons: 1. Generally this is done for all tables on the page and 2. to keep the number of initialisation options manageable and sane :-)

    Allan
  • kaukaskaukas Posts: 4Questions: 0Answers: 0
    edited May 2011
    > you can easily do it with just regular DOM or jQuery methods. $().addClass() etc

    Yes but only:
    - after the initialisation is complete (after .dataTable({}) call) or
    - for the elements that are there before the initialisation (table, thead, tbody, ...)

    Thank you!
This discussion has been closed.