Dynamic option name upon table initialization
Dynamic option name upon table initialization
ludalex
Posts: 4Questions: 0Answers: 0
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