Destroying table breaks out of parent function

Destroying table breaks out of parent function

shdyjashdyja Posts: 1Questions: 1Answers: 0

Working on a part of a page that dynamically shows a preview of the data that would be returned from a query. It works on the first pass, but if a user were to change the query I obviously need the table to reload. The code runs as below and in the first run will be in the else clause. The problem comes when dTable is not null. When dtTable.fnDestroy() gets called it simply exits the function that contains all of this code and goes to the calling line before it. Is this the appropriate way to delete/recreate a table? Using version 1.9.4

function setupTabs(data) {
var clmns = [];
jQuery.each(data.Columns, function (i, value) {
    clmns.push({ "mDataProp": value, "sTitle": value });
});

if (dtTable != null) {
    // Quickly and simply clear a table
    dtTable.fnClearTable();

    // Restore the table to it's original state in the DOM
    dtTable.fnDestroy();

    dtTable = $('#DataPreviewTable').DataTable({
        "aaData": data.OutputData,
        "aoColumns": clmns,
        "bFilter": false,
        "bInfo": false,
        "bLengthChange": false,
        "bDestroy": true
    });
} else {
    dtTable = $('#DataPreviewTable').DataTable({
        "aaData": data.OutputData,
        "aoColumns": clmns,
        "bFilter": false,
        "bInfo": false,
        "bLengthChange": false,
        "bDestroy": true
    });
}
dtTable.fnDraw();
}

Thanks.

This discussion has been closed.