通过使用
columns.dataDT
选项用于告诉Datatables找到每一列的数据源对象中对应的属性。
下面例子的数据模型如下:
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$3,120",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
}
Name | Position | Office | Extn. | Start date | Salary |
---|---|---|---|---|---|
Name | Position | Office | Extn. | Start date | Salary |
$(document).ready(function() { $('#example').DataTable( { "ajax": "data/objects.txt", "columns": [ { "data": "name" }, { "data": "position" }, { "data": "office" }, { "data": "extn" }, { "data": "start_date" }, { "data": "salary" } ] } ); } );
<table id="example" class="display" cellspacing="0" 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>
Translation from DataTables.net, with permission