当从 Ajax 源加载数据,在默认情况下,数据表将寻找要使用返回的对象的数据参数中的数据 (例如 {"data": [......]})。
通过使用 ajaxDT选项的dataSrc 启动选项来改变属性。
dataSrc有许多用法如下:
dataSrc: 'myData',下面的例子展示的是这个用法dataSrc:"" dataSrc: function(json) {} (您可以从 XML 转换到一个 Javascript 对象) | Name | Position | Office | Extn. | Start date | Salary |
|---|---|---|---|---|---|
| Name | Position | Office | Extn. | Start date | Salary |
$(document).ready(function() {
$('#example').dataTable( {
"ajax": {
"url": "data/arrays_custom_prop.txt",
//默认为data,这里定义为demo
"dataSrc": "demo"
}
} );
} );
<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>
http://datatables.net/examples/ajax/custom_data_property.html
Translation from DataTables.net, with permission