Dynamic option name upon table initialization
Dynamic option name upon table initialization
![ludalex](https://secure.gravatar.com/avatar/55a5b4a854521980482ded05320fb6fe/?default=https%3A%2F%2Fvanillicon.com%2F55a5b4a854521980482ded05320fb6fe_200.png&rating=g&size=120)
Hello everyone,
I'm trying to write a function that loads the table with different sources (ajax/javascript array) dynamically.
Instead of writing the code to initialize the table twice in a conditional statment, I'd like to have the "source" option of the DataTable to come from a variable, as shown in this example:
[code]
if (navigator.onLine)
source_ = 'sAjaxSource'
else
source_ = 'aaData'
oTable = $('#table').dataTable({
"sDom": 'Tfrt',
source_: data
})
[/code]
It doesn't work as expected tough, any suggestions?
I know 'data' variable is not defined and the actual data source is not my problem as if I put a string like "aaData" instead of 'source_' (the option name) it works.
Thanks in advance
I'm trying to write a function that loads the table with different sources (ajax/javascript array) dynamically.
Instead of writing the code to initialize the table twice in a conditional statment, I'd like to have the "source" option of the DataTable to come from a variable, as shown in this example:
[code]
if (navigator.onLine)
source_ = 'sAjaxSource'
else
source_ = 'aaData'
oTable = $('#table').dataTable({
"sDom": 'Tfrt',
source_: data
})
[/code]
It doesn't work as expected tough, any suggestions?
I know 'data' variable is not defined and the actual data source is not my problem as if I put a string like "aaData" instead of 'source_' (the option name) it works.
Thanks in advance
This discussion has been closed.
Replies
[code]
function src () {
var o;
if ( ... ) {
o.aaData = [];
}
else {
o.sAjaxSource = ...;
}
}
oTable = $('#table').dataTable( $.extend( true, src(), {
sDom: ...
} );
[/code]
Allan