Adjust the datatables filters correctly with diferent words [duplicate]
This question already has an answer here:
Match whole string
3 answers
I have a datatable with several columns.
One of them is id=event
To filter by "Event" I release a modal with a multiple select2 (id=event_filter) and by clicking on the Send button (id=filter-button) I launch the following code by javascript.
$(document).ready(function (e) {
let table = $('#datatable-table').DataTable();
$('#filter-button').click(function (e) {
e.preventDefault();
let str = $('#event_filter').find(':selected').map(function() {
return $( this ).text();
})
.get()
.join( "|" );
if (str.length > 0){
console.log(str);
table
.columns($('th#event'))
.search(jQuery.fn.DataTable.ext.type.search.string(str),true,false )
.draw();
} else {
table
.columns($('th#event'))
.search("")
.draw();
}
})
})
Among the select options are:
-Natal
-Pre Natal
-Post Natal
The problem is: When I select ONLY Natal, the console.log (str) returns Natal, but the table filters Natal, Pre Natal and Post Natal.
The behavior you must have is:
I select Natal => Only the rows with Natal appear
Select Natal and Pre Natal => appear only rows with Pre Natal and Natal
What am I doing wrong?
jquery regex datatables
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 15:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Match whole string
3 answers
I have a datatable with several columns.
One of them is id=event
To filter by "Event" I release a modal with a multiple select2 (id=event_filter) and by clicking on the Send button (id=filter-button) I launch the following code by javascript.
$(document).ready(function (e) {
let table = $('#datatable-table').DataTable();
$('#filter-button').click(function (e) {
e.preventDefault();
let str = $('#event_filter').find(':selected').map(function() {
return $( this ).text();
})
.get()
.join( "|" );
if (str.length > 0){
console.log(str);
table
.columns($('th#event'))
.search(jQuery.fn.DataTable.ext.type.search.string(str),true,false )
.draw();
} else {
table
.columns($('th#event'))
.search("")
.draw();
}
})
})
Among the select options are:
-Natal
-Pre Natal
-Post Natal
The problem is: When I select ONLY Natal, the console.log (str) returns Natal, but the table filters Natal, Pre Natal and Post Natal.
The behavior you must have is:
I select Natal => Only the rows with Natal appear
Select Natal and Pre Natal => appear only rows with Pre Natal and Natal
What am I doing wrong?
jquery regex datatables
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 15:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Match whole string
3 answers
I have a datatable with several columns.
One of them is id=event
To filter by "Event" I release a modal with a multiple select2 (id=event_filter) and by clicking on the Send button (id=filter-button) I launch the following code by javascript.
$(document).ready(function (e) {
let table = $('#datatable-table').DataTable();
$('#filter-button').click(function (e) {
e.preventDefault();
let str = $('#event_filter').find(':selected').map(function() {
return $( this ).text();
})
.get()
.join( "|" );
if (str.length > 0){
console.log(str);
table
.columns($('th#event'))
.search(jQuery.fn.DataTable.ext.type.search.string(str),true,false )
.draw();
} else {
table
.columns($('th#event'))
.search("")
.draw();
}
})
})
Among the select options are:
-Natal
-Pre Natal
-Post Natal
The problem is: When I select ONLY Natal, the console.log (str) returns Natal, but the table filters Natal, Pre Natal and Post Natal.
The behavior you must have is:
I select Natal => Only the rows with Natal appear
Select Natal and Pre Natal => appear only rows with Pre Natal and Natal
What am I doing wrong?
jquery regex datatables
This question already has an answer here:
Match whole string
3 answers
I have a datatable with several columns.
One of them is id=event
To filter by "Event" I release a modal with a multiple select2 (id=event_filter) and by clicking on the Send button (id=filter-button) I launch the following code by javascript.
$(document).ready(function (e) {
let table = $('#datatable-table').DataTable();
$('#filter-button').click(function (e) {
e.preventDefault();
let str = $('#event_filter').find(':selected').map(function() {
return $( this ).text();
})
.get()
.join( "|" );
if (str.length > 0){
console.log(str);
table
.columns($('th#event'))
.search(jQuery.fn.DataTable.ext.type.search.string(str),true,false )
.draw();
} else {
table
.columns($('th#event'))
.search("")
.draw();
}
})
})
Among the select options are:
-Natal
-Pre Natal
-Post Natal
The problem is: When I select ONLY Natal, the console.log (str) returns Natal, but the table filters Natal, Pre Natal and Post Natal.
The behavior you must have is:
I select Natal => Only the rows with Natal appear
Select Natal and Pre Natal => appear only rows with Pre Natal and Natal
What am I doing wrong?
This question already has an answer here:
Match whole string
3 answers
jquery regex datatables
jquery regex datatables
edited Nov 11 at 13:29
asked Nov 11 at 13:19
Jose
409
409
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 15:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 15:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Finally I found the solution:
return '^'+$(this).text()+'$';
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Finally I found the solution:
return '^'+$(this).text()+'$';
add a comment |
Finally I found the solution:
return '^'+$(this).text()+'$';
add a comment |
Finally I found the solution:
return '^'+$(this).text()+'$';
Finally I found the solution:
return '^'+$(this).text()+'$';
answered Nov 11 at 14:33
Jose
409
409
add a comment |
add a comment |