Referencing datatables after initialisation.

Referencing datatables after initialisation.

kpzanikpzani Posts: 1Questions: 0Answers: 0
edited August 2012 in General
I have solved my own problem but want to know if there's a cleaner way of doing it.

I am using a PHP templating system so in the template file I initialise all datatable objects using the following code:

[code]$('.jquerytable').dataTable( {
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap"
} );[/code]

On a certain page then I want to change the default sorting options and couldn't find a way to get a handle on the datatable object. So I was forced to maintain an array of the datatable objects.

My initialisation code became:
[code]
$('.jquerytable').each(function(index) {
STP_Datatables[$(this).attr('id')] = $(this).dataTable ({
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap"
} );
});[/code]

then I can access each datatable from the array
[code]$('#dtProjects').ready(function() {
STP_Datatables['dtProjects'].fnSort( [ [0,'desc'] ] );
});[/code]

but it seems that I should be able to use some of the static functions to get access to these.

Am I missing something or is my solution ok?
This discussion has been closed.