我希望能够从直接传递给DataTables的动态信息创建一个表,而不是使用DataTables(jQuery Javascript库的插件)从文档中读取它
我有这张桌子
var dataSet = [
['IOS-LSLSLS','PRODUCT-NAME','CATEGORY','MANUFACTURER','COUNTRY','RETAILER1, RETAILER2'],
['ANDROID-LSLSLS','PRODUCT-NAME2','CATEGORY2','MANUFACTURER2','COUNTRY2','RETAILER31, RETAILER32']];
oTable = $('#devicesDatatableId').dataTable( {
"stateSave": true,
"bStateSave": true,
"data": dataSet,
"sScrollY": "auto",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"aaSorting": [[ 0, "asc" ]],
"aoColumnDefs": [
{ "bSortable": false, "asSorting": [ "asc" ], "sWidth": "15%", "aTargets": [ 0 ] },
{ "sWidth": "20%", "aTargets": [ 1 ] },
{ "sWidth": "10%", "aTargets": [ 2 ] },
{ "sWidth": "20%", "aTargets": [ 3 ] },
{ "sWidth": "15%", "aTargets": [ 4 ] },
{ "sWidth": "20%", "aTargets": [ 5 ] }
],
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"bSortCellsTop": true,
"sDom": 'tlpi<"clear">',
});
和
<table cellpadding="0" cellspacing="0" border="0" class="display normaltable" id="devicesDatatableId">
<thead>
<tr>
<th >Model</th>
<th >Product name</th>
<th >Category:</th>
<th >Manufacturer:</th>
<th >Country(ies):</th>
<th >Retailer(s):</th>
</tr>
<tr class="thefilters">
<td ><input name="" size="" maxlength="" id="" value="" type="text"/></td>
<td ><input name="" size="" maxlength="" id="" value="" type="text"/></td>
<td ><input name="" size="" maxlength="" id="" value="" type="text"/></td>
<td ><input name="" size="" maxlength="" id="" value="" type="text"/></td>
<td ><input name="" size="" maxlength="" id="" value="" type="text"/></td>
<td ><input name="" size="" maxlength="" id="" value="" type="text"/></td>
</tr>
</thead>
<tfoot>
<tr>
<th>Model</th>
<th>Product name</th>
<th>Category:</th>
<th>Manufacturer:</th>
<th>Country(ies):</th>
<th>Retailer(s):</th>
</tr>
</tfoot>
<tbody/>
</table>
但表格中没有数据
答案 0 :(得分:1)
从结尾处删除双引号:
var dataSet = [['IOS-LSLSLS','PRODUCT-NAME','CATEGORY','MANUFACTURER','COUNTRY','RETAILER1, RETAILER2'],
['ANDROID-LSLSLS','PRODUCT-NAME2','CATEGORY2','MANUFACTURER2','COUNTRY2','RETAILER31, RETAILER32']];
以下是工作版本:jsfiddle