JQuery Datatable Question: centering column data after data entry

I have a data table that is initially empty and populated after a specific Javascript call. After the data is inserted into the table, I would like to concentrate all the data in one of the columns. I tried to indicate this at the initialization stage as follows:

dTable = $('#dt').datatable({ 'aoColumns': [ null, null, { "sClass" : "center" }] });

The data in the third column was not centered after the insertion was completed. I tried changing aoColumns after insertion and redrawing the table:

dTable.fnSettings().aoColumns[2].sClass = "center";
dTable.fnDraw();

That didn't work either. So my question is, how should I report the data center data table in the third column?

Thanks in advance for your suggestions.

Chris

+5
1

, AJAX. . :

$.ajax({
  url: 'ajax/test.html',
  success: function(data) { //after AJAX completes
    //fill the table.
    $('#dt').children('tr').each(function(){ //for each row
      $(this).children('td').eq(2).attr('align', 'center');  //center the third column.
    });
  }
});

, , . attr (attributeName, value) . css (propertyName, value) .addClass().

+2

All Articles