Table won't refresh

Table won't refresh

morefiercemorefierce Posts: 3Questions: 1Answers: 0
edited June 2014 in Free community support

I'm very new to all of this, please be patient with me! I've searched through the forums but all the suggested solutions have not worked for me so far. I'm stumped. This is what I have:

var oTable;
$(document).ready(function() {
    oTable= $('#example').dataTable( {
        "ajax": {
            "url": "../cgi-bin/tableshow.cgi",
            "type": "POST"
        },
        "columns": [
            { "data": "col0" },
            { "data": "col1" },
            { "data": "col2" },
            { "data": "col3" }
        ]
    } );
} );

var tablerefresh = function(stringin){
    var xhrname = new XMLHttpRequest();
    xhrname.onreadystatechange = function(){
        if (xhrname.readyState == 4){
            oTable.ajax.reload();
        }
    };
    xhrname.open("POST","../cgi-bin/tableupdate.cgi",true);
    xhrname.setRequestHeader("Content-Type", "text/plain");
    xhrname.send(stringin);
};

tablerefresh is triggered by an external event. It is being triggered all right, yet oTable.ajax.reload(); doesn't do anything, nor does .fnStandingRedraw();, or .fnDraw();, or .ajax.reload();, or .fnReloadAjax();, or even .fnReloadAjax("../cgi-bin/tableshow.cgi");. Somehow, other things like .fnClearTable(); have their expected effects though. If anyone could point me in the right direction I would be so grateful! Thanks!

Answers

  • morefiercemorefierce Posts: 3Questions: 1Answers: 0

    Finally found a working workaround in the end: destroy then reinitialise. Obviously clunky. Please let me know if there's a better way.

    oTable.fnDestroy();
    oTable= $('#example').dataTable( {
    ...
    
  • allanallan Posts: 55,060Questions: 1Answers: 8,643 Site admin

    yet oTable.ajax.reload(); doesn't do anything

    I'd be willing to bet that it was throwing a Javascript error. Look in the console to see the error in your browser.

    See the second top FAQ for why that is the case.

    Allan

  • morefiercemorefierce Posts: 3Questions: 1Answers: 0

    Thanks so much Allan! oTable.api().ajax.reload(); did it, bad oversight on my part. Thanks.

This discussion has been closed.