is it possible to get the table selector in an extension method
is it possible to get the table selector in an extension method

Hi,
i was wondering if its possible to get the table selector "the table id passed on init" in an extension method somehow? i assume at the extension point datatables is already initialised so it should hold the data somewhere?
im building an extension on: $.fn.dataTable.ext.oSort
the idea being, i extend the settings allowing the specification of date columns and their formats and then i use moment.js on the sorting extension level to convert that into a generic format for processing, this way dates can be displayed however people like without the restriction to specific formats. I require the table selector as i will be using that as the key to store the column format in against that particular datatables instance "allowing it to work for multiple table instances"
Answers
In most cases yes, it is possible, but not for the sorting plug-ins. The idea for them was that they should not be table specific, but rather a given format would be consistent across all tables. For example, you wouldn't sort
).
YY dd mm
differently in two different tables (indeed, you wouldn't actually use that daft format at all, but its an exampleRegarding the issue you are looking at, have you seen my blog post on this topic? It seems to be basically the same sort of thing.
Allan
Morning Allan,
thanks for your feedback, i did indeed look over your blog post and unfortunately it is specific for a single format as your mentioned, i think over the weekend i have managed to crack it but i need to do some further testing to be sure.
To make it work for different formats on different table instances on the same page here is basically what i did "but i am still testing this at the moment":-
Create an extension method of the options and added a date column array to be specified and a date column format to be specified for that table instance
I then used a generic type name and added the format to it:-
"type": "date-search-" + settings["datecolumnsformat"],
then while i was checking some other processes i created the oSort extension for that specific format in terms of pre, asc and desc formats if it does not exist.
in the long term i am building a generic bootstrap datatables wrapper with column search functionality, date range functionality and tick boxes etc which i intend to open source once its ready. The idea being you will be able to use datatables with bootstrap by using the wrapper and all the hard work of creating extra search columns, or date range search capability will be taken care of by default.
having done some more testing i can confirm this functionality is working as expected, when two completely different date moment formats are defined as well as table data it correctly sorts on both the initialised tables for different formatted dates correctly.
You can add as many different formats as you want on the same page with my plug-in. Just call the function multiple times.
Allan
o, after looking at it if i thought the following:-
if i called the moment function and initialised a datatable and then wanted to do this for a separate table on the same page the moment function would override the current format that has been passed to it as its a global function not local to the table instance, is this not correct?
also to be honest i could not seem to get the plugin working with the latest version of datatables, there was no error, it simply just would not do anything in terms of sorting the date column supplied.
No. Multiple detected formats can co-exist. If you have a look at the code, for every format the plug-in is called with it creates auto detect and sorting plug-ins.
If you give me a link to the page with the issue I'd be happy to take a look at it and help debug it.
The blog post I linked to uses DataTables 1.10.12 which is the current release.
Allan