General settings object, retrieving the datatable object....
General settings object, retrieving the datatable object....
ellipsis
Posts: 23Questions: 0Answers: 0
Hello,
First of all, datatables absolutely rocks!
I'm using several tables and use a general settings object which I merge with table specific settings.
It all works great but I've som annoying redundant code, because I can't seem to retrieve the table object within the general settings object.
I tried :
[code]datatable_default_setting.oColVis = : { 'aiExclude': pfx_determineWhichColumnsToHideFromColVis(this.fnSettings().aoColumns),'buttonText':''}; [/code]
of course the 'this' reference is seen as the datatable_default_setting object.
Best regards,
René
First of all, datatables absolutely rocks!
I'm using several tables and use a general settings object which I merge with table specific settings.
It all works great but I've som annoying redundant code, because I can't seem to retrieve the table object within the general settings object.
I tried :
[code]datatable_default_setting.oColVis = : { 'aiExclude': pfx_determineWhichColumnsToHideFromColVis(this.fnSettings().aoColumns),'buttonText':''}; [/code]
of course the 'this' reference is seen as the datatable_default_setting object.
Best regards,
René
This discussion has been closed.
Replies
Where the table object is the `` node and the general settings object is the return from fnSettings ? You can use the `nTable` property of the settings object.
DataTables 1.10's API will have a much more obvious `table().node()` method...!
Allan
Iĺl give a more exact example:
[code]
var ob_settings = {
'sDom': main_object.datatables_default_sdom,
'oLanguage': {'sUrl': main_object.datatables_dutch_url},
'sScrollY': '1',
'bProcessing': true,
'bServerSide': false,
'oColVis' : { 'aiExclude': fnc_determineWhichColumnsToHideFromColVis(this.fnSettings().aoColumns),'buttonText':''}
};
function create_table_1(){
var ob_custom_settings = { 'aoColumns' : ..... };
jQuery('#table_1').dataTable(jQuery.extend(ob_settings, ob_custom_settings));
}
function create_table_2(){
var ob_custom_settings = { 'aoColumns' : ..... };
jQuery('#table_2').dataTable(jQuery.extend(ob_settings, ob_custom_settings));
}
function create_table_3(){
var ob_custom_settings = { 'aoColumns' : ..... };
jQuery('#table_3').dataTable(jQuery.extend(ob_settings, ob_custom_settings));
}
function create_table_4(){
var ob_custom_settings = { 'aoColumns' : ..... };
jQuery('#table_4').dataTable(jQuery.extend(ob_settings, ob_custom_settings));
}
[/code]
As you can see they all share the same settings object (ob_settings) (what I would like to set as default for the dataTable object but didn't succeed yet)
The colvis aiExclude is the example I'm using here, needs the datatable object to retrieve its settings (in this case the aocolumns)
How do I make this work?
Allan
I tried, but I still have the same issue then.
And setting the default the way it is intended is certainly the best way, but the TableTools swf custom location setting does not seem to get across.
The question still remains:
How do I get (for example) the aoColumns object inside a function in the default settings....
Beyond that, you might want to do a deep copy in jQuery extend.
> How do I get (for example) the aoColumns object inside a function in the default settings....
Generally speaking you don't - what are you trying to do? Perhaps I can suggest another way.
Allan
Thank you for the reply, sorry for my late response.
I would like to be able to retrieve (for example) the aocolumns object inside a new defined default settings.
Because the columns have a sClass value that determines if the columns should be visible in ColVis for example. The functio I use returnes the array of columns to exclude from colvis.
[code]'oColVis' : { 'aiExclude': fnc_determineWhichColumnsToHideFromColVis(aoColumns) } [/code]
now I write custom settings for each table with the above repeated code...
DataTables 1.10 has the ability to give you column index information based on a jQuery selector. For example:
[code]
// gives an array of the column indexes which are hidden
$('#example').DataTable().columns(':not(:visible):jq').index();
// gives an array of the column indexes which are not hidden
$('#example').DataTable().columns(':visible:jq').index();
// gives an array of the column indexes based on a class
$('#example').DataTable().columns('.myClass:jq').index();
[/code]
The `:jq` postfix tells the column selector to treat the first part as a jQuery selector on the header cells.
DataTables 1.10, which is currently pre-beta, can be obtained here: https://github.com/DataTables/DataTables/tree/1_10_wip/media/js
Allan
This would be the solution!!
I'm not so brave at the moment, the code will be used a lot and should be reliable.
Can't wait on the release!!
Thank you so much!!!!
Still a question though:
when setting this as default for each datatable:
[code]
'oColVis' : { 'aiExclude': jQuery(this).DataTable().columns('.myClass:jq').index();}
[/code]
I must asume it will not work, the THIS is the default settings object....
Any Suggestions
Allan