Jquery Datatables filter for full phrase

Asked

Viewed 501 times

0

I’m using Jquery datatables, I always use it, but today I have a situation that I did not find in his documentation. And the following, when the query is done it brings me the value of several fields comparing by words, I need the search to be done by the full sentence in all columns and not comparing word by word of all columns.

  • If you write the phrase in the filter it does so automatically

  • Yes friend, but he picks up the words in several columns. He does not query for the whole sentence.

  • 1

    You can put the phrase in double quotes, so it looks for the exact phrase.

  • @Renatodiniz Killed the riddle friend. And I can stop it without quotation marks?

  • With the quotes worked, I have a bank where I need to filter in the description column and with other columns of status. Where they mixed. The bank is big, and yet it only happens in some situations.

  • @Williancoqueiro added an answer explaining how to do this without quotation marks.

  • It took me a while to understand your need, but then I researched deeper and found in the documentation

  • I fucked in the documentation 30 min kkkk

Show 3 more comments

2 answers

2

You can search by placing the text in double quotes or disable the Datatable Smart Search function by adding this setting when starting the table:

$('#tabela').dataTable({
  "search": {
    "smart": false
  }
});

1


search smart. enables intelligent filter activation and inactivation

Smart filter:

Breaks the user input into individual words and then corresponds to those words at any position and in any order in the table (instead of simply making a simple string comparison).

https://datatables.net/reference/option/search.smart

$('#example').dataTable( {
  "search": {
    "smart": false
  }
} );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">

<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
        <tbody>
            <tr>
                <td>Paul Byrd</td>
                <td>Chief Financial Officer (CFO)</td>
                <td>New York</td>
                <td>64</td>
                <td>2010/06/09</td>
                <td>$725,000</td>
            </tr>
            <tr>
                <td>Yuri Berry</td>
                <td>Chief Marketing Officer (CMO)</td>
                <td>New York</td>
                <td>40</td>
                <td>2009/06/25</td>
                <td>$675,000</td>
            </tr>
            <tr>
                <td>Angelica Ramos</td>
                <td>Chief Executive Officer (CEO)</td>
                <td>London</td>
                <td>47</td>
                <td>2009/10/09</td>
                <td>$1,200,000</td>
            </tr>
       </tbody>
    </table>

  • Buddy, can you tell me if you can reverse the search name with the search field? You know, the search ta on the left side, and the input ta on the right side. I wanted to reverse them.

  • actually just you access the dataTables, that’s where he removed this example code, and so will have all clarification

Browser other questions tagged

You are not signed in. Login or sign up in order to post.