[英]How to do search with first letter in individual column searching datatable
I'am working on a web app with datatable.我正在开发一个带有数据表的网络应用程序。 I've done global research bar and individual research bar, like this example: https://datatables.net/examples/api/multi_filter.html Now what I want to do is to start research by the first letter only in the individuals columns.我已经完成了全局研究栏和个人研究栏,就像这个例子: https : //datatables.net/examples/api/multi_filter.html现在我想做的是只在个人列中按第一个字母开始研究. I tried to do this whith global research and it worked fine, thank to this :我试图通过全球研究来做到这一点,并且效果很好,这要归功于:
$(document).ready(function() {
var table=$('#example').DataTable( {
responsive: true
} );
$('.dataTables_filter input').on( 'keyup', function (e) {
var regExSearch = '\\b' + this.value;
table.search(regExSearch, true, false).draw();
});
} );
But this is not what I want And I have programmed my individual research like that :但这不是我想要的而且我已经对我的个人研究进行了这样的编程:
table.columns(':gt(1)').every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search(this.value )
.draw();
}
} );
} );
I tried to use the same logic as global research while adding .search('\\\\b' +this.value )
but when I try to search something, nothing is returned.在添加.search('\\\\b' +this.value )
时,我尝试使用与全局研究相同的逻辑,但是当我尝试搜索某些内容时,没有返回任何内容。
Maybe I do something wrong, does anyone know how to do that ?也许我做错了什么,有人知道该怎么做吗?
Ok I was so close.好吧,我离得很近。 The only thing I had to do is :我唯一要做的是:
table.columns(':gt(1)').every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search('\^'+this.value, true, false ) // regex=true, smart=false
.draw();
}
} );
} );
And it work.它工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.