Set Options Programmatically (after table initialization)

Set Options Programmatically (after table initialization)

coreyocoreyo Posts: 5Questions: 0Answers: 0
edited February 2011 in General
I have been looking for an example of a way to set one of the datatable options after initialization. More specifically, in this case, I want to set column types (i.e. 'aoColumnDefs') just above or below the HTML table definition. Can anyone show me how to do this?

Even better would be a way to specify column type in an HTML attribute in the header. Is there currently a way to do that?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    You can't really do it after initialisation (actually you can - but it's not recommended), but you can certainly do it during or before. It sounds like you might want to use the aoColumnDefs option of matching on class names. For example:

    [code]
    "aoColumnDefs": [
    {
    "sType": "whatever",
    "aTargets": [ "myClass" ]
    },
    {
    "sType": "whatever2",
    "aTargets": [ "mySecondClass" ]
    }
    ]
    [/code]
    Then just put 'myClass' on the TH elements you want to use sType of 'whatever'.

    Allan
  • coreyocoreyo Posts: 5Questions: 0Answers: 0
    Excellent allan,
    This is definitely a very jQuery way of doing things, and I could certainly use it. Is there a way to match on anything other than css class (i.e. like with any of the other jQuery selectors?).
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    No - currently indexes (0+ counting from the left, <0 counting from the right, classes and "_all" - http://datatables.net/usage/columns ) are the only options. Extending this to be more of a selector is certainly an option though.

    Allan
  • coreyocoreyo Posts: 5Questions: 0Answers: 0
    Not a problem, just curious on that last part. Was finally about to get everything sorting properly as a result, despite blank entries. Thanks for the replies.
This discussion has been closed.