【发布时间】:2017-03-27 07:57:07
【问题描述】:
//我正在尝试使用 DataTable 插件创建表,我需要为表中的每一列单独过滤列, 我正在使用 javascripted 资源获取数据 https://jsfiddle.net/ImmanuelRocha/zu0h3yca/ 例如:https://datatables.net/examples/data_sources/js_array.html
var dataSet = [
["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"]];
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each(function() {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
// DataTable
var table = $('#example').DataTable({
data: dataSet,
columns: [{
title: "Name"
}, {
title: "Position"
}, {
title: "Office"
}, {
title: "Extn."
}, {
title: "Start date"
}, {
title: "Salary"
}]
});
// Apply the search
table.columns().every(function() {
var that = this;
$('input', this.footer()).on('keyup change', function() {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});
【问题讨论】:
标签: javascript jquery datatable