【发布时间】:2016-08-30 09:40:53
【问题描述】:
花了几天时间尝试了我在互联网上找到的许多解决方案后,我 在这里问。
当点击搜索按钮时,我的表单会显示一个包含数据的表格。该表有 8 列,我想在其中 3 列上添加一个文本输入,使用该文本输入应用具有列数据的过滤器。为了更好地了解我的需求,请访问JsFiddle showing a working column filter。
所以,我尝试了上面链接和Datatable exemple 的解决方案,但没有成功,找不到我做错了什么。
这是我的代码:
<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();
});
aaData使用的result是我在ajax上搜索Rest方法成功得到的json。我在该成功方法上填充表格。
所以我的问题是:我做错了什么或误解了什么?
我试图将对象equipmentTable.column($(this).data('index')).search(this.value) 与示例中返回的内容进行比较并获得等效对象。这就是为什么我几乎可以肯定问题出在 draw() 方法上。
感谢您的帮助。
【问题讨论】:
标签: jquery datatables datatables-1.10 jquery-2.0