DataTables 是一個在資金所限但又要用DataGrid 情況下的一個替代品. 透過JQuery, 可以將資料從JSON 中顯示出來.
看了教學, 其實使用不難. 最簡單從Web Request 存取資料方法如下:
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<SCRIPT type="text/javascript">
$(document).ready(function() {
$('#example').DataTable( {
"ajax": "http://www.aaa.com",
"data": function ( d ) {
"active": true
}
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
</script>
初步用上來算不錯. 但若與Angular 等比較, 沒有Binding 是它最大的失敗之處. 希望有機會它可以將它整合到Angular / React 這類Framework 中吧.
參考資料
- DataTables, SpryMedia Ltd,
https://datatables.net/
Leave a Reply