destroy table option

destroy table option

pwc1011pwc1011 Posts: 62Questions: 0Answers: 0
edited February 2010 in General
Allan,

I tested (not as extensively as your test cases) the following as an option to include for destroying the table.

[code]
/* Sanity check that we are not re-initialising a table - if we are, alert an error if not a destroy */
for (i = 0, iLen = _aoSettings.length; i < iLen; i++) {
if (_aoSettings[i].nTable == this) {
if (oInit.destroy == true) {
_aoSettings.splice(i, 1);
return;
}
else {
alert("DataTables warning: Unable to re-initialise DataTable. " +
"Please use the API to make any configuration changes required.");
return _aoSettings[i];
}
}
}

// if still here and destroy was called, then the table not found
// so return
if (oInit.destroy == true) {
return;
}
[/code]

This can be called as follows:

[code]
$("#example").dataTable({"destroy":true});

// to remove the table from page... could be added to DataTables destroy.
$("#example").remove();
[/code]

May not the best long-term solution, but it's an idea.

One more thing... Because of the way DataTables is constructed with private and public functions, this doesn't affect any other tables in a multi-table situation.

Patrick

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Patrick,

    Yup - that is not a bad idea at all. I quite like the idea of a dev being allowed to do it intentionally, but they get the alert() if not. I think I'd like to complete the destructor to restore the DOm to it's original state - but that should be perfectly do-able... One for a future version this I think. Thanks.

    Allan
  • pwc1011pwc1011 Posts: 62Questions: 0Answers: 0
    Actually, if you remove the comment, it's a nice way to return the handle to a table already created :0

    Patrick
  • psykepsyke Posts: 5Questions: 0Answers: 0
    edited March 2010
    Hello,

    First of all I wanted to thank you for your great work. It's really awesome.

    I would like to "refresh" my table after an Ajax call.
    I tried several pieces of code to refresh my table but none of them worked.

    my original resulting html code when I arrive on my page:

    [code]






    hdata1

    hdata2

    hdata3

    hdata4

    hdata5




    data1


    data2

    data3

    data4


    data5






    //<![CDATA[

    jQuery.noConflict();

    var oTable;
    function initDataTablesList(){
    jQuery(document).ready(function($) {
    oTable = $('#list_handledList').dataTable( {
    "bPaginate": true,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    "bAutoWidth": true,
    "oLanguage": {
    "sProcessing": "Chargement...",
    "sLengthMenu": "Afficher _MENU_ r
  • newbietonienewbietonie Posts: 3Questions: 0Answers: 0
    Hi Patrick,

    I tried to incorporate your code from the one you posted on this thread,
    It get rid of the alert Warning but it displays- 2 Show entries, search box, showing label at the bottom..

    any idea on this one?
    I'm a newbie in jquery so bare with me..

    thanks for the help in advance..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    DataTables has changed quite a lot since the work Partick was doing above, given that there is now a built in destroy option, which should be used, if you do need to that that.

    It's probably best to start a new thread for this subject now, ideally with a link and your initialisation code :-). I guess you are initialising the table times - which you probably don't want to do...

    Allan
This discussion has been closed.