Data-tables not bringing back exact results.

Alex Lord
Alex Lord used Ask the Experts™
on
  function getContacts(listId, cOnly) {

            if (typeof contactTable !== 'undefined')
                contactTable.destroy();
            contactTable = $('#contactstable').DataTable({
                "serverSide": true,
                "stateSave": true,
                "ordering": false,
                "searching": true,
                "oSearch": {"bSmart": false},
                "searchDelay": 1500,
                "ajax": {
                    "url": "get-contacts.php",
                    "type": "POST",
                    "data": {
                        listId: listId,
                        co: cOnly
                    }
                },
                "rowCallback": function (row, data) {
                },
                "initComplete": function (data) {
         
                },
                "columns": [
                    {"data": "contact"},
                    {"data": "email"},
                    {"data": "company"},
                    {"data": "date"},
                    {"data": "actions"}
                ],
                'columnDefs'        : [      
                { 
                    'searchable'    : false, 
                    'targets'       : [2,3,4] 
                }
            ],
                "order": [[0, 'desc']]
            });


     
        }

Open in new window



so this function creates my dataTable,

all works table it up, i only perform search functions on contact and email,

how ever it is failing to give me exact results , for example first record is  Tim Smith , i can clearly see Tim Smith, i type Tim Smith into the search input provided by data-tables, and he isnt shown in the result ?

https://datatables.net/
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Pretty sure the actual search (filtering) will be done at your server-side script because you've set the datasource to AJAX, so to understand why it's not working, we'd need to see the get-contacts.php file
Hi,

Check if you have any html tag around the name.
The search and filter option supposed to work the same even if you use their server-side method, because it looking once the table is rendered...

Which Datatables version are you using?
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Actually, just checked - its not because you're using an AJAX datasource - it's because you've set the serverSide property to true. This tells DataTables that you'll handle it yourself at the server end. Remove that (or set it to false) and you'll see that it works. If you want more advance searching, then re-enable the server-side property and handle the search server-side (build your own query)
See here that is possible to search or filter data that are rendered using server-side
https://datatables.net/examples/server_side/simple.html

As long as the data you are looking for is in the datatables table

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial