作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个表,我想手动搜索。查看 API 后,我发现我可以这样做:
table.search(somestring).draw();
这应该搜索表格并重新绘制它,至少我是这么认为的。
$(document).ready(function(){
var table = $('table').DataTable({
searching: false,
paging: false,
info: false
});
// add a bunch of rows
for(var i=0; i<20; i++){
table.row.add([
"test "+i, "best "+i, "rest "+i
]);
}
// draw the table
table.draw();
// why won't table redraw with only rows containing 15?
table.search('15').draw();
// this doesn't work either
/*
$('input').on( 'keyup click', function () {
filterColumn( 1 ); // filter only first column
} );
*/
});
function filterColumn ( i ) {
console.log( $('input').val() );
$('table').DataTable().column( i ).search(
$('input').val()
).draw();
}
HTML:
<input>
<table>
<thead>
<tr>
<th>column 1</th>
<th>column 2</th>
<th>column 3</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
最佳答案
您已通过 searching: false
禁用了搜索功能,请参阅 searching选项了解更多详细信息。
您需要使用 searching: true
启用搜索或删除此选项才能使 search()
方法正常工作。
如果您只是想隐藏过滤控件,请使用dom: 'lrtip'
,参见dom选项了解更多详细信息。
关于javascript - 为什么手动搜索后DataTable不会重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31279933/
我是一名优秀的程序员,十分优秀!