Rerendering of Column Titles

Rerendering of Column Titles

J0shJ0sh Posts: 1Questions: 0Answers: 0
edited February 2012 in General
Hey @all,

i want to add columns dynamically to the data table depending on a json result, which is requested from a server. I'm using the fnReloadAjax PlugIn and i have some problems to solve this task.

Is there a function which renders not only the data part of the table but also the "table header". I mean is there a function which rerenders the column names?

This part is resetting the aoColumns array an reinitializes it:
var aColumns = that.oApi._fnGetObjectDataFn("aoColumns")(json);
oSettings.aoColumns = [];
for ( var i = 0; i < aColumns.length; i++) {
that.oApi._fnAddColumn(oSettings, i);
oSettings.aoColumns[i].sTitle = aColumns[i].sTitle;
}

This part should rerender the table. But only the data part is rerendered:
that._fnBuildHead(oSettings);
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
that._fnDrawHead(oSettings, oSettings.aoHeader);
that._fnReDraw(oSettings);

Can anyone help me?

Best regards,
J0sh

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    DataTables does not currently support dynamically adding and removing columns to and from the table I'm afraid. I'm sure its perfectly possible to write an API method for it, but I've not yet had time to do so, and there isn't one available that I'm aware of from the wider community.

    If your column count is always going to be identical, then you can just use standard DOM methods to write the contents of the header cells - the only time DataTables writes to then is on initialisation, and even then only if required. Again this could be wrapper up into an API plug-in :-)

    Allan
This discussion has been closed.