在花了几天时间尝试了我在互联网上找到的许多解决方案后,我在这里问。
我有一个表格,当点击搜索按钮时,它会显示一个包含数据的表格。该表有 8 列,在其中的 3 列上,我想添加一个文本输入,用于应用具有列数据的过滤器。为了更好地了解我的需要,JsFiddle 显示了一个工作列过滤器。
所以,我尝试了上面链接和Datatable 示例的解决方案,但没有成功,找不到我做错了什么。
有我的代码:
<table id="EquipmentTable" class="table table-striped table-bordered bottom-buffer" width="100%">
<thead>
<tr>
<th><input type="checkbox" name="select_all" value="1" id="checkAll" class="text-center" onclick="$.fn.backboneSearch.checkAllResult()"></th>
<th>Equipement</th>
<th>Famille d'équipement</th>
<th>Gamme d'équipement</th>
<th>Etat</th>
<th>UI</th>
<th>Site de stockage</th>
<th>Salle technique</th>
<th></th>
</tr>
</thead>
<tfoot id="backboneSearchtfoot">
<tr id="filterrow">
<th></th>
<th id="textFilter1" class="textFilter"></th>
<th id="textFilter2" class="textFilter"></th>
<th id="textFilter3" class="textFilter"></th>
<th class="listFilter"></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
// Setup - add a text input to each footer cell
$('#EquipmentTable tfoot th.textFilter').each(function (i) {
$(this).html('<input type="text" data-index="' + i + '" />');
});
equipmentTable = $('#EquipmentTable').DataTable({
aaData: result,
aoColumns: [
{ mData: 'Identifier' },
{ mData: 'Mnemo' },
{ mData: 'FamGam.Family' },
{ mData: 'FamGam.Gamme' },
{ mData: 'dataState.Libelle' },
{ mData: 'IdentifierUI' },
{ mData: 'TechnicalRoom.InterventionUnitySenderSite' },
{ mData: 'IdentifierTechnicalRoom' },
],
bDestroy: true,
bFilter: false,
bRetrieve: true,
buttons: [{
className: 'btn-warning',
columns: [1, 2, 3, 4, 5, 6],
extend: 'excel',
fieldSeparator: ';',
text: '<span class="glyphicon glyphicon-export"></span> Export'
}],
dom: 'Bfrtip',
language: { /*not useful to show*/ },
stateSave: true,
bProcessing: true
});
$(equipmentTable.table().container()).on('keyup', 'tfoot th.textFilter input', function () {
equipmentTable.column($(this).data('index'))
.search(this.value)
.draw();
});
使用result
的aaData
是一个json,我在搜索Rest方法的ajax成功。我在该成功方法上填充表格。
所以我的问题是:我做错了什么或误解了什么?我试图将对象equipmentTable.column($(this).data('index')).search(this.value)
与示例中返回的对象进行比较并获得等效对象。这就是为什么我几乎可以肯定问题来自 draw() 方法。
谢谢您的帮助。