select rows after search

select rows after search

montoyammontoyam Posts: 568Questions: 136Answers: 5

Is it possible after a search is performed to select the rows that are displayed. I plan on having a button that the user will press only if they get one result from each of the dataTables on the page that will select the row in each of the tables.

I currently have a single search box that performs a search on all three.

        /* search all DataTables at once */
        $.fn.dataTable.ext.search.push(
            function (settings, data, dataIndex) {
                //console.log(settings.nTable.id);
                if (settings.nTable.id == '#Departments') { return true; }

                var searchFor = $('#searchFor').val().toLowerCase();
                if (searchFor == undefined || searchFor == '') {
                    return true;
                } else {
                    var searchItems = searchFor.split(" "); //user can hide multiple items, separated by a space
                    var result = false;
                    for (index = 0; index < searchItems.length; index++) {
                        if (searchItems[index]) {
                            if (data.toString().toLowerCase().includes(searchItems[index])) {
                                result = true
                            } else return false;
                        }
                    }
                    return result;
                }

            }
        );

        $('#searchFor').keyup(function () {
            PhoneBookTable.draw();
            StanUsersTable.draw();
            FNDUsersTable.draw();
        });

Answers

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    ahh, sorry, i seem to have found the solution:

            $('#searchFor').keyup(function () {
                PhoneBookTable.draw();
                StanUsersTable.draw();
                FNDUsersTable.draw();
                if (PhoneBookTable.page.info().recordsDisplay == 1) {
                    PhoneBookTable.row(':eq(0)', { page: 'current' }).select();
                }
                if (StanUsersTable.page.info().recordsDisplay == 1) {
                    StanUsersTable.row(':eq(0)', { page: 'current' }).select();
                }
                if (FNDUsersTable.page.info().recordsDisplay == 1) {
                    FNDUsersTable.row(':eq(0)', { page: 'current' }).select();
                }
                
            });
    
This discussion has been closed.