Configuring server side Datatables for an unknown number of tables

Go To StackoverFlow.com

0

I am using DataTables with the tables being generated in a java controller class that talks to the database. Given a category id, the controller class returns an unknown number of preformatted HTML tables, one for each section in the given category queried. Ideally I would like to display each table as a DataTable on the same page, but unsure if that's possible given that I don't know how many tables I will be getting back so I can't set up their behavior before the query.

Is there a way to format the tables when/as I get them from the controller? I attempted to prepend each table with its own .ready block but that didn't seem to do the trick though I'm fairly new to jQuery and could just be missing something. I used the barest of configuration to try to get it working first

     $(document).ready(function(){
            $("#results").dataTable({
                "bJQueryUI" : true
            });
        });
2012-04-04 00:24
by ItinerantEngineer
How is the page asking for the data? Ajax? (server-side enabled and url provided in DataTables options) Or is the server returning a rendered page containing an unknown number of tables - Greg Pettit 2012-04-04 03:54
The JSP page looks for an attribute set in the request, which if it is set, contains an unknown number of HTML tables - ItinerantEngineer 2012-04-04 17:06


0

$(document).ready(function() {
$('.dataTable').dataTable();
} );

Turns out to work after all, but ONLY if you specify the tables as class="dataTable" which isn't well documented or explained, hopefully this un-confuses someone else!

2012-04-05 01:08
by ItinerantEngineer
Ads