fnDrawCallback, the table isn't rendered yet

fnDrawCallback, the table isn't rendered yet

nsinhansinha Posts: 5Questions: 0Answers: 0
edited March 2014 in General
I have an mRender for one of my columns that has the format "%s". When I attempt to retrieve $('.jTip') in fnDrawCallback, it never finds anything. After the last fnDrawCallback, the table is finally displayed, and $('.jTip') finds all the items it should. Is this expected behavior? I thought fnDrawCallback gets called after the entire table is in the DOM.

Replies

  • systematicalsystematical Posts: 23Questions: 0Answers: 0
    Sample code?
  • nsinhansinha Posts: 5Questions: 0Answers: 0
    [code]$('#SearchBatchTable').dataTable({
    bJQueryUI: false, //themeroller support
    bStateSave: true, //save sort state across F5 screen refresh
    bPaginate: false,
    sScrollY: fnCalcDataTableHeight(305),
    "sScrollX": "100%",
    "bScrollCollapse": true,
    bInfo: false,
    bFilter: false,
    bAutoWidth: true,
    aoColumnDefs: [
    {
    aTargets: [0],
    bSortable: true,
    sWidth: "30px",
    sType: "numeric"
    },
    {
    aTargets: [1],
    bSortable: true,
    sWidth: "280px",
    mRender: function (data, type, row) {
    var linkFormat = "%s";
    var col1Parts = data.split(";");
    var formattedValues = vsprintf(linkFormat, col1Parts);
    return formattedValues;
    }
    },
    {
    aTargets: ["_all"],
    sWidth: "175px",
    bSortable: false,
    }
    ],
    bSortClasses: false, //disable the highlighting of the sort column
    bProcessing: false,
    sAjaxSource: url,
    fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
    $('td', nRow).each(function (index) {
    var that = $(this);
    var inner = aData[index + 2];
    that.empty();
    var parts = inner.split(';');
    that.attr('data-s', parts[0]);
    that.attr('data-d', parts[1]);
    that.attr('title', parts[2]);
    that.addClass('statusCell');
    });

    },
    fnInitComplete: function () {
    postInitializeTable();
    }

    });[/code]

    I renamed fnDrawCallback to fnInitComplete. It works on the first call, but I want it to happen every time I do an ajax refresh, just after all the dom elements are available to jQuery.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    `$('.jTip')` will only get the nodes that are visible. DataTables doesn't put the nodes which are not visible into the DOM.

    Use `this.$('.jTip')...` in fnInitComplete to get all of the elements - see: http://datatables.net/docs/DataTables/1.9.4/#$
  • nsinhansinha Posts: 5Questions: 0Answers: 0
    If fnDrawCallback happens after everything is drawn, why aren't the nodes visible?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    The ones on the current page are. The ones of the other pages are not because they not in the document. They are only inserted when needed.

    Allan
This discussion has been closed.