Datatables event on all tables on page
Datatables event on all tables on page
The plugin is great, but I just can't find the way to do a really simple thing. It seems that all the examples show a way to control tables when you assign a js variable for each of them. That's ok for most cases, but I need to have unknown number of tables on a page and make event handler for them all. If I want to use resize event examples say:
var oTable= $('.datatable').dataTable();
$(window).resize(function(){
oTable.fnAdjustColumnSizing();
});
OK. But what if I want to make something like:
$(window).resize(function(){
$('.datatable').fnAdjustColumnSizing();
});
I know this doesn't work and I just have no way to access datatables object for a table on page if I have no variable associated. The problem is that on a page I use ajax calls and create different tables with them dynamically in modal boxes. I even sometimes have 3 or 4 dialogs on top of each other and they all have tables. I use a simple script of mine for this moment, but data is large and everything runs slow, so datatables would be a great alternative as I may use server side processing. But is there a way to find a reference to the datatables objects from tables that have been converted? Using an array is not an option too as most tables will be destroyed and new ones will be created as you stay on page- I create an MVC style application.
var oTable= $('.datatable').dataTable();
$(window).resize(function(){
oTable.fnAdjustColumnSizing();
});
OK. But what if I want to make something like:
$(window).resize(function(){
$('.datatable').fnAdjustColumnSizing();
});
I know this doesn't work and I just have no way to access datatables object for a table on page if I have no variable associated. The problem is that on a page I use ajax calls and create different tables with them dynamically in modal boxes. I even sometimes have 3 or 4 dialogs on top of each other and they all have tables. I use a simple script of mine for this moment, but data is large and everything runs slow, so datatables would be a great alternative as I may use server side processing. But is there a way to find a reference to the datatables objects from tables that have been converted? Using an array is not an option too as most tables will be destroyed and new ones will be created as you stay on page- I create an MVC style application.
This discussion has been closed.
Replies
How to do it atm:
1. Loop over the $('.datatable') elements width jQuery's each. Then you can call $(this).dataTable().fnAdjustColumnSizing() on each.
2. Use the $.fn.dataTablesSettings array which contains a copy of the settings object for every table on the page. You can loop over that and use the oInstance parameter to call the API method.
Allan
[code]
var s= $.fn.DataTable.settings;
for ( i=0, iLen=s.length ; i