search doesn't work

search doesn't work

gib65gib65 Posts: 29Questions: 13Answers: 0

Hello,

I'm experimenting with the DataTable and I'm trying out the search functionality here:

https://datatables.net/reference/api/column().search()

It doesn't seem to work.

I try the search in the table initiatization and through the API as follows:

[code]
$(document).ready(function() {
var t = $('table_id').DataTable({
paging: false,
scrollY: 100,
searchCols: [
null,
{search: 'Row 2'}
});

 t.columns(1).search('Row 2').draw();

});
[/code]

My table ends up looking like the attachment. In other words, row #2 is not filtered out. There's no indication to show that it has been searched.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Either of those options should work. Don't see an attachment so not sure of the problem.

    I would suggest providing test cases with your issues:
    https://datatables.net/manual/tech-notes/10

    Kevin

  • gib65gib65 Posts: 29Questions: 13Answers: 0

    Thanks for the reply kthorngren,

    I have made an example of the issue I am having at:

    http://www.shahspace.com/dtexample/

    Working Table is an example of a table that is working fine.

    Broken Table (scrollX) is an example of a table whose scrollX property I have set to true. As you can see, it not only fails to display a horizontal scroll bar, but messes up the layout of the table.

    Search not Working is an example I provided for my other thread (https://datatables.net/forums/discussion/40965/search-doesnt-work#latest). It shows a table with an initial search in the config and also a search call on the second column through the API, like so:

    var t = $('#table_3').DataTable({
    searchCols: [
    null,
    {search: 'Row 2'}
    ]
    });
    t.columns([1]).search('Row 2').draw();

    ...but nothing to indicate that 'Row 2' has been found, or filtered out, or highlighted, etc. in rows 2.

    Thanks for any help you might be able to give.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited March 2017 Answer ✓

    For scrollX to work properly you need to add the width="100%" attribute to your table_2:

    <table id="table_2" class="display" width="100%">
    

    By default search() has Smart Search enabled which it matches any of the words in the search. In the case of Row 2 any row that matches Row or 2 will be a match. You can either disable Smart Search (and regex) like this:

    t.columns([1]).search('Row 2', false, false).draw();
    

    Or you can search for the full string by enclosing it in quotes (notice the double quotes inside the single quotes), like this:

    t.columns([1]).search('"Row 2"').draw();
    

    The same for searchCols:

            searchCols: [
                null,
                {search: '"Row 2"'}
            ]
    

    Also, if you are going to use the jQuery UI you should also use the DataTables styling libraries for jQuery UI. You can get them from here:
    https://datatables.net/download/index

    You will need DataTables-1.10.13/css/dataTables.jqueryui.min.css and DataTables-1.10.13/js/dataTables.jqueryui.min.js in addition to what you have.

    Kevin

  • gib65gib65 Posts: 29Questions: 13Answers: 0

    Thanks Kevin, those suggestions helped.

This discussion has been closed.