How to search in only one table when multiple tables exist.

How to search in only one table when multiple tables exist.

hwyckoffhwyckoff Posts: 19Questions: 7Answers: 1

I have a jQuery function with these variable definitions:

            var oTable = $(".display").DataTable();               
            var table1 = oTable.table("#InterventionAverage");
            var table2 = oTable.table("#InterventionSummary");
            var table3 = oTable.table("#InterventionDetails");

And while I can do column visibility code, like this:

            table1.column(3).visible(false, false);

I cannot do specific searching within only one table.

            var selection = getMergedSelections();
            table3.search(selection.join('|'), true, false, true);

How can I search only within a specific table?

This question has an accepted answers - jump to answer

Answers

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

    I'm not sure what your search term is and if it will work but you do need to update the search display by drawing the table. Try this:

    table3.search(selection.join('|'), true, false, true).draw();

    This is from the search() docs:

    In order to have the search performed and the result shown, use the draw() method, which can be called simply as a chained method of the search() method's returned object - for example table.search( 'Fred' ).draw();.

    Kevin

  • hwyckoffhwyckoff Posts: 19Questions: 7Answers: 1

    I did it as you wrote, and it's still not working.

  • hwyckoffhwyckoff Posts: 19Questions: 7Answers: 1

    @kthorngren -- Here's a twist. When I do this:

                table2.search(selection.join('|'), true, false, true).draw();
                table3.search(selection.join('|'), true, false, true).draw();
    

    The search applies on table 2 but not table 3.

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

    Seems to work here:
    http://live.datatables.net/gasepoci/1/edit

    Maybe you can update my test case with your specifics.

    Kevin

  • hwyckoffhwyckoff Posts: 19Questions: 7Answers: 1

    @kthorngren -- It was a rookie mistake on my part. The table ID was actually assigned to the outer div. Rookie mistake and I finally saw it after taking a walk from the computer.

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

    finally saw it after taking a walk from the computer.

    Happens all the time.

    Kevin

This discussion has been closed.