如何更改 JQuery.DataTable 中单元格的样式? [英] How do you change the style of cell in a 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" }
] } );
这篇关于如何更改 JQuery.DataTable 中单元格的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!