如何更改JQuery.DataTable中单元格的样式?
我有一个关于在 jQuery.DataTable
中设置数据单元格的样式属性的问题。使用以下代码初始化 dataTable
时,可以设置每列的宽度:
I have a question about setting the style attributes for a data cell in the jQuery.DataTable
. I was able to set the width for each column when initializing the dataTable
using the following code:
oTable = $('#example').dataTable( {
"aoColumns" : [
{ sWidth: '40%' },
{ sWidth: '60%' }
]
} );
现在我要更改第二列的对齐方式: style =text-align:right;
。
Now I want to change the alignment for the second column like so: style="text-align: right;"
.
我正在使用以下代码动态添加行:
I am adding rows dynamically using this code:
/* Global var for counter */
var giCount = 2;
function fnClickAddRow() {
oTable.fnAddData( [
'col_1',
'col_2' ] );
giCount++;
}
你能告诉我如何选择新行的第二个单元格
Can you tell me how can I select the second cell of the new row after it's been inserted OR how to set the style of the row before/during insertion?
任何帮助将不胜感激!
很高兴,我很高兴地报告我能够回答自己的问题!我刚刚定义了一个CSS样式(alignRight),并将样式添加到列中:
Cool, I am happy to report that I was able to answer my own question! I just defined a CSS style (alignRight), and added the style to the column like so:
<style media="all" type="text/css">
.alignRight { text-align: right; }
</style>
oTable = $('#example').dataTable( {
"aoColumns" : [
{ sWidth: '40%' },
{ sWidth: '60%', sClass: "alignRight" }
] } );