Multiple tables

Multiple tables

gutzoftergutzofter Posts: 58Questions: 0Answers: 0
edited July 2010 in General
I'm creating multiple tables. I'm using qunit to unit test.
my code is:
[code]
$('table[id^=print_tbl]').each(function() {
var holder = $('#' + this.id).dataTable({
bDestory: true,
bSort: true,
bFilter: true
});
var index = this.id;
tables[index] = holder;

});
[/code]

I need to have access to each individual table, because i then send each tables sorted and filtered to the server.
[code]
var vendorData = {};
var table = tables[index];

if ($('#' + index).is(':visible')) {
vendorData[index] = table.fnGetDisplayedData();
}
return vendorData;

[/code]

this appears to work except, I end up with about 62 items dataTableSettings. They are duplicates. I looked at you code at line 5987:
[code]
if ( _aoSettings[i].nTable == this )
[/code]

This doesn't let me destroy the tables.

Replies

  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    Here is an actual failing test in qunit:

    [code]
    var tables = newVendorTables();
    var myTestTablesContent = '';
    var messageEvent = {
    content: function(url) {
    $.ajax({
    type: 'GET',
    url: url,
    async: false,
    success: function(content) {
    myTestTablesContent = content;
    }
    });
    }
    };
    messageEvent.content('../../application/batch.print.php');

    module("test for dataTables", {
    setup: function() {
    $('').appendTo('body');
    $('.contentContainer').html(myTestTablesContent);
    tables.initTables();
    },
    teardown: function() {
    $('.contentContainer').remove();
    }
    });

    should('validate that there is only two tables in dataTableSettings destroy all tables', function() {
    $('.contentContainer').remove();
    $('').appendTo('body');
    $('.contentContainer').html(myTestTablesContent);
    tables.initTables();

    var createdTables = tables.getTables();
    var table = createdTables['print_tbltest'];
    same(table.dataTableSettings.length, 2);
    });
    [/code]
  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    By appending and removing the html elements for the tables between tests cause new elements to be created. dataTable then think these are actually new tables even though they have the same ids. I will try to create new tests using your framework and patch code to fix this.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I've replied in your other thread: http://datatables.net/forums/comments.php?DiscussionID=2308 . Perhaps if you could have a look at my post there, and we can keep just one thread going :-)

    Regards,
    Allan
This discussion has been closed.