omitting rather than include the matching results from that search
omitting rather than include the matching results from that search
NehaC
Posts: 20Questions: 5Answers: 0
For example -
if you type “hello” into the name search field, only results that DO NOT INCLUDE “hello” in the name will appear in the results.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Some buddy please help, me
You will need to a Search Plugin for the comparison and your own search
input
to trigger the plugin. See this Range Search example for a running example of a search plugin.Kevin
Hello Kelvin,
But this solution is not working for me.
Please tell me another solution.
What did you try? Can you build a simple test case showing what you are trying?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
How I can try this solution to name field ?
Here is an example:
http://live.datatables.net/kisamiju/1/edit
It removes the matching items in the Office column. Type
London
into theRemove
search input.Kevin
Need a 2 check box
1) To enable/disable Regular expression
2) To omitting rather than include the matching results
below need code in if statement
var table = $('#example').Datatable()
$('#example thead tr:eq(1) th').each( function (i) {
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
}
Hope so, You understood my problem.
This example is working looking at, since it's doing mostly what you're looking for.
Colin
Hello Colin,
I saw this example, I have done To enable/disable Regular expression.
I want a solution for this To omitting rather than include the matching results
For example -
if you type “hello” into the name search field, only results that DO NOT INCLUDE “hello” in the name will appear in the results in the data table
The example I provided does this. If you want to enable or disable this using a checkbox then within the search plugin example I provide you can get the state of the checkbox and if unchecked, for example, return true, like this snippet of code:
Kevin
Hello Kelvin,
I understood this example but I didn't understand how to add in if a condition so please give me solution.
can you please check this example -
1) the first checkbox is disabled/endable regular expression
2) To omitting rather than include the matching results from that search
Here is my code
I need code in if the condition of not_equal checkbox i.e if the second check box is checked true then
http://live.datatables.net/qunodalu/1/edit
so give me solutions
Maybe this example will give you a start.
http://live.datatables.net/pezecuyu/1/edit
I moved the header clone above the Datatables init so the sorting events aren't cloned. I added
orderCellsTop
to move the sorting events to the top row.I changed this code:
If the not_equal checkbox is checked then the column search is cleared. Otherwise you will end up with conflict column search and not_equal search removing all rows from the table.
I added the search plugin to loop through all cells in the row getting the not_equal checkbox state and the text input for comparison.
Likely this needs more work. Hope it gets you started.
Kevin
I saw your example and its working as per my requirements but the below function not called and I don't know when this function is called
so can you tell me how can I call this function explicitly?
$.fn.dataTable.ext.search.push(
function( settings, searchData, index, rowData, counter ) {
// Loop through all columns and get the checkbox state and input value
for (i=0; i<searchData.length; i++) {
var checked = $('#not_equal_' + i).prop('checked');
console.log( "&&&&& ")
// hide row if checked and input matches cell
if (checked && $('#text_box'+i).val() === searchData[i]) {
return false;
}
}
return true;
}
The search plugin is called anytime the Datatable is drawn, for example searching, sorting and paging will draw the Datatable. The
draw()
in line 8 in my last code snippet is used to call the search plugin. Also thedraw()
in line 15 calls the plugin.Kevin
Okay. I have written a console Statement but it was not printing that statement also.
Did you update the test case to show the problem?
Kevin
Here the test case -
http://live.datatables.net/qunodalu/1/edit
Please check once.
Why did you remove this code (line 5 above) from my example?
As I explained this is needed to clear any searches in that column otherwise all the rows will be filtered. I added back to your example:
http://live.datatables.net/qunodalu/2/edit
Kevin
Hello Kevin,
In the example, it's working fine but I don't know when I use the same code in my current project it's not working.
http://live.datatables.net/qunodalu/1/edit
Its hard to say without seeing the problem. Can you post a link to your page or update the test case to show the issue?
Look for errors in the browser's console.
Use the browser's debugger to trace your code to see where its not working.
Kevin