【发布时间】:2016-09-15 23:05:27
【问题描述】:
使用的数据表是 1.10.12 版本
我会假设以下工作,但事实并非如此。我的意思是除了搜索字段之外的所有其他工作,它们都没有出现。从服务器获取JSON数据绘制表格。
这里是 HTML:
<span>
<table name="item" id="item" class="display" width="100%" cellspacing="0">
</table>
</span>
javascript:
$(document).ready(function(){
//################# initial table draw
var oTable; //global
var rowIndexGlobal = 0;
var colIndexGlobal = 0;
$.getJSON( "item.pl?Action=getlist", function( data ) {
var dataSet = [];
$.each( data, function( key, val ) {
dataSet.push(val);
});
oTable = $('#item').DataTable({
data: dataSet,
columns: [
{ title: "ID" },
{ title: "Item" },
{ title: "Inventory" },
{ title: "Price" },
{ title: "Sale" },
],
"fnInitComplete": function() {
$('#item tbody tr').each(function(){
$(this).find('td:eq(3)').attr('nowrap', 'nowrap'); //making text to NOT-wrap.
});
$("#datatables4_wrapper").css("width","100%");
//this did not work so i have commented out
/*var r = $('#item tfoot tr');
r.find('th').each(function(){
$(this).css('padding', 8);
});
$('#item thead').append(r);
$('#search_0').css('text-align', 'center');*/
},
"bAutoWidth": false
});
// Sort by columns 1 and 9 and redraw <- it works, but search does not....
oTable
.order( [ 1, 'asc' ], [ 9, 'asc' ] )
.draw()
.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
});
});
});
});
我还希望将这些搜索框放在标题下,作为表格的第一行....
此代码来自网站,为什么它不起作用?
【问题讨论】:
标签: jquery datatable datatables datatables-1.10