Possible to set DataTable sorting options via the HTML?

Possible to set DataTable sorting options via the HTML?

sm9sm9 Posts: 27Questions: 0Answers: 0
edited April 2013 in DataTables 1.9
Hi there,

I've got a website with lots of tables, and each one has different columns, column types, etc.

I'm currently calling them all with a single JS call for any table that has a class of 'sortable-table'. This is convenient and means there's less lines of code than if I had calls for every single individual table.

However, I've got half a dozen tables that I want to use aoColumns sType sorting on. In order to do this, I think I'm going to have to have an individual call for these tables in my JS, which is going to be tedious (as each of these tables has different columns).

So my question (finally) is, is it possible to specify these values via classes on the table itself? So rather than use aoColumns and '{ "sType": "uk_date" }, in my functions.js file, can I specify this via the actual table row itself, e.g. Date Submitted or similar?

Thanks,

Ste

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    There is no built in way of doing this. There is nothing to stop you from using a bit of jQuery and reading the properties from the HTML and then constructing the required initialisation option.

    I've often thought of writing a plug-in which will do that. Never got around to it yet though... Hopefully once v1.10 is out...

    Allan
  • sm9sm9 Posts: 27Questions: 0Answers: 0
    My jQuery is not very good, so I'd have to wait until some kind soul added this feature I think. :-) There's a similar feature when using jQuery validate actually, where you can add a class of "required" to fields to make the validation kick in.

    Thanks,

    Stephen
  • VisionstarVisionstar Posts: 7Questions: 1Answers: 0
    Hey!

    Please add that Functionality, i would really appreciate that!

    (Y)

    Thanks!
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Will be doing so in future :-)
This discussion has been closed.