JQuery Datatable问题:数据插入后居中列数据

时间:2010-05-16 23:53:19

标签: javascript jquery jquery-ui datatable

我有一个最初为空的数据表,并在特定的Javascript调用后填充。将数据插入表后,我想将所有数据集中在其中一列中。我尝试以这种方式在初始化步骤中指定它:

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

插入完成后,第三列中的数据未居中。我尝试在插入后修改aoColumns并重新绘制表格:

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

这也不起作用。所以我的问题是我应该如何告诉数据表将数据置于第三列中心?

提前感谢您的建议。

克里斯

1 个答案:

答案 0 :(得分:2)

如果我理解正确,您的表将获得多行,其中包含来自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()添加类。