Question

are there any way to add new column to the table with JQuery plugin DataTables?

Was it helpful?

Solution

Well it depends on what you need it for... if you just want to have columns hidden, then reveal them at a later time, then you'd do this to toggle the column (from the docs)

function fnShowHide( iCol )
{
  /* Get the DataTables object again - this is not a recreation, just a get of the object */
  var oTable = $('#example').dataTable();

  var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
  oTable.fnSetColumnVis( iCol, bVis ? false : true );
}

The plugin doesn't have an interface (as far as I'm aware) for adding columns, but ordinary jQuery seems to do the trick:

$('#example thead tr,#example tfoot tr').append('<th>New title</th>');
$('#example tbody tr').append('<td />');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top