Searching only on the previous search set

Searching only on the previous search set

kjkiddkjkidd Posts: 13Questions: 4Answers: 0
edited July 2015 in Free community support

My current function (below) searches based on the data returned from right-clicking a cell. The problem is the search results are always based on ALL the data. I'm trying to get it to continue to drill down using only data from the previously applied search.

$('#sr_table tbody').on( 'mousedown', 'td', function (e) { if( e.button == 2 ) { searchData = table.cell(this).data(); table.search( searchData).draw(); } } );

I have also tried to use table.columns({search:'applied', order:'applied'}).search( searchData).draw(); , but that produces no results every time.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    You are basically replacing the previous search when you call the search() method with a value. What you would need to do is get the current search term (which you can do with that same method) and then append the additional search term.

    Allan

  • kjkiddkjkidd Posts: 13Questions: 4Answers: 0
    edited July 2015

    Thanks for the idea. To implement it, I ended up having to do some less than ideal manipulations on the array to get it to work. For some reason when I just put the raw array into search() |DT, it wasn't working correctly.

    var searchTerms = [];
    $('#sr_table tbody').on( 'mousedown', 'td', function (e) {
    if( e.button == 2 ) {

                    searchData = table.cell(this).data();
                    searchTerms.push("\"" + searchData + "\"");
                    var terms = searchTerms.join(", ");
                    table.search(terms).draw();
                 }
            } );
    
This discussion has been closed.