问题描述
假设我写在数据搜索框'b'中,那么它通常会显示'abc','ybu','break','brain'等等,但是我只想得到'break','brain'与b)。这意味着当我写一些字,它会显示我的话,从那开始。i am using yajra DataTables 1.10.10。
修改
我解决了这个问题,但是当我尝试使用两个数据表时,现在面临新的prob
,它停止显示一个datatable tbody数据,而另一个datatable正常工作
$。fn.dataTableExt.afnFiltering.push(
function(oSettings,aData,iDataIndex){
var keywords = $(。dataTables_filter input)。val .split('');
var matches = 0;
for(var k = 0; k< keywords.length; k ++){
var keyword = keywords [k];
for(var col = 0; col< aData.length; col ++){
if(aData [col] .charAt(0).toLowerCase()== keyword.charAt(0).toLowerCase()) {
匹配++;
break;
}
}
}
返回匹配== keywords.length;
}
) ;
$('。table2id')。dataTable({
});
$('。table1id')。dataTable({
});
终于解决了
var ptable = $('#table2')。DataTable();
var rtable = $('#table1')。DataTable();
var term;
$('#table1_filter input [type =search]')。keyup(function(e){
console.log(table1_filter);
var term = $ ).val();
regex ='^'+ term;
rtable.column(0).search(regex,true,false).draw();
});
$('#table2_filter input [type =search]')。keyup(function(e){
term = $(this).val();
regex ='^'+ term;
ptable.column(0).search(regex,true,false).draw();
});
最终答案: / p>
var ptable = $('#table2')DataTable();
var rtable = $('#table1')。DataTable();
var term;
$('#table1_filter input [type =search]')。keyup(function(e){
console.log(table1_filter);
var term = $ ).val();
regex ='^'+ term;
rtable.column(0).search(regex,true,false).draw();
});
$('#table2_filter input [type =search]')。keyup(function(e){
term = $(this).val();
regex ='^'+ term;
ptable.column(0).search(regex,true,false).draw();
});
另一个解决方案:(不适用于同一页面中的多个数据表) / p>
$。fn.dataTableExt.afnFiltering.push(
function(oSettings,aData,iDataIndex){
var keywords = $(。dataTables_filter input)。val()。split('');
var matches = 0;
for(var k = 0; k< keywords.length; k ++) {
var keyword = keywords [k];
for(var col = 0; col< aData.length; col ++){
if(aData [col] .charAt(0).toLowerCase ()== keyword.charAt(0).toLowerCase()){
matches ++;
break;
}
}
}
return matches = = keywords.length;
}
);
$('。tableid')。dataTable({
});
Suppose i write in datatable search box 'b' then it will normally show 'abc','ybu','break','brain' etc .but i want to get only 'break','brain' (start with b).that means when i write something word ,it will show me word that start with that.i am using yajra DataTables 1.10.10.
Edit
i solved this prob but now facing new probwhen i try to use two datatables ,it stop to show one datatable tbody datas but another datatable work properly
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex) {
var keywords = $(".dataTables_filter input").val().split(' ');
var matches = 0;
for (var k=0; k<keywords.length; k++) {
var keyword = keywords[k];
for (var col=0; col<aData.length; col++) {
if (aData[col].charAt(0).toLowerCase() == keyword.charAt(0).toLowerCase()) {
matches++;
break;
}
}
}
return matches == keywords.length;
}
);
$('.table2id').dataTable({
});
$('.table1id').dataTable({
});
finally solved it
var ptable = $('#table2').DataTable();
var rtable = $('#table1').DataTable();
var term;
$('#table1_filter input[type="search"]').keyup(function(e){
console.log("table1_filter");
var term = $(this).val();
regex = '^' + term ;
rtable.column( 0 ).search( regex, true, false ).draw();
});
$('#table2_filter input[type="search"]').keyup(function(e){
term = $(this).val();
regex = '^' + term ;
ptable.column( 0 ).search( regex, true, false ).draw();
});
Final answer:
var ptable = $('#table2').DataTable();
var rtable = $('#table1').DataTable();
var term;
$('#table1_filter input[type="search"]').keyup(function(e){
console.log("table1_filter");
var term = $(this).val();
regex = '^' + term ;
rtable.column( 0 ).search( regex, true, false ).draw();
});
$('#table2_filter input[type="search"]').keyup(function(e){
term = $(this).val();
regex = '^' + term ;
ptable.column( 0 ).search( regex, true, false ).draw();
});
Another Solution:(not work for multi datatables in same page)
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex) {
var keywords = $(".dataTables_filter input").val().split(' ');
var matches = 0;
for (var k=0; k<keywords.length; k++) {
var keyword = keywords[k];
for (var col=0; col<aData.length; col++) {
if (aData[col].charAt(0).toLowerCase() == keyword.charAt(0).toLowerCase()) {
matches++;
break;
}
}
}
return matches == keywords.length;
}
);
$('.tableid').dataTable({
});
这篇关于如何更改yajra dataTable搜索过滤系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!