我們使用DataTables jQuery插件(http://www.datatables.net)創建可排序的表。該插件可以自動檢測每列中數據的數據類型。使用<th>屬性爲DataTable指定列數據類型
如果要指定自己列的數據類型,您添加「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>
...
有沒有辦法做到這一點,無論是與數據表的默認功能(我可以」 t查找)或使用JS循環或其他東西來循環表中的標籤,並更新其中「sType」屬性存在的sType?
使用HTML自定義數據屬性 - 只需在構建配置數據結構時選擇其內容。 – CBroe 2013-03-22 16:23:08