【发布时间】:2013-03-22 16:00:30
【问题描述】:
我们正在使用 DataTables jQuery 插件 (http://www.datatables.net) 创建可排序表。该插件自动检测每列数据的数据类型。
当你想自己指定一个列的数据类型时,你在初始化数据表时添加“aoColumns”属性:
$('#accountTable').dataTable({
"bPaginate": false,
"sScrollX": "100%",
"bScrollCollapse": true,
"aoColumns": [
null,
null,
{ "sType": "currency" },
{ "sType": "currency" }
]
});
注意,我下载了数据表的货币数据类型插件。这很好用。
但是,我担心如果我们对表列进行更改,我们会忘记返回 JS 并更改数据表插件在该表上的初始化方式。
所以...根据需要直接在表中指定数据类型是理想的:
<table class="dataTables display">
<thead>
<tr>
<th>Category</th>
<th>Product</th>
<th sType="currency">Cost</th>
<th sType="currency">Retail</th>
...
有什么办法可以做到这一点,要么使用 DataTables 的默认功能(我找不到),要么使用 JS 循环或其他东西来循环表的标签并更新存在“sType”属性的 sType ?
【问题讨论】:
-
使用 HTML 自定义数据属性——在构建配置数据结构时只需选择它们的内容。
标签: javascript jquery datatables