Adding two contains for a .each()

joetinger

I have a table with two filters a search box and a selectbox. In the end I would like the search box filter to only search the table entries filtered by the selectbox.

For example: Pending Qualification is selected in the selectbox, so only rows with Pending Qualification are showing (the rest are hidden). When I search I only want to search the visible rows.

Ideally I would like to add another condition before the .each(function(e))

I tried this but it doesn't seem to work.

CSS

.hidden {
    display:none;
}

Here is containsi

$.extend($.expr[':'], {
    'containsi': function (elem, i, match, array) {
        return (elem.textContent || elem.innerText || '').toLowerCase()
        .indexOf((match[3] || "").toLowerCase()) >= 0;
    }
});//end of case insensitive chunk

Below attempts don't work

All of these still filter all the data

$("#filterItems .hideThis").not(":containsi('" + searchSplit + "'):contains('"+ selectValue + "')").each(function (e) {
    //add a "hidden" class that will remove the item from the list
    $(this).addClass('hidden');
});

next

$("#filterItems .hideThis").not(":containsi('" + searchSplit + "')").each(function (e) {
    if($("#filterItems .hideThis:contains('" + selectValue + "')")){
       //add a "hidden" class that will remove the item from the list
       $(this).addClass('hidden');
    }
});

I also tired checking for .hidden

$("#filterItems .hideThis").not(":containsi('" + searchSplit + "')").each(function (e) {
    if(!($(this).hasClass('hidden'))){
        //add a "hidden" class that will remove the item from the list
        $(this).addClass('hidden');
    }
});

Current JSFiddle if you would like to see it

undefined

You are making it complicated, I'd suggest:

$('#select-Qualification').on('change', filter).change();
$("#search-text").on('keyup', filter).keyup();

function filter() 
{
    var selectValue = $('#select-Qualification').val();
    var query = $.trim($("#search-text").val()).toLowerCase();

    // filter based on the select's value
    var $col = $("#filterItems .hideThis").addClass('hidden').filter(function () {
        return $('td:eq(3)', this).text() === selectValue;
    });

    // filter based on the search input's value
    if (query.length) {
        $col = $col.filter(function() {
           return $(this).text().toLowerCase().indexOf(query) > -1;
        });
    }

    $col.removeClass('hidden');
}

http://jsfiddle.net/5LaxC/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Adding two contains for a .each()

From Dev

Adding two tuples and applying a function to each element

From Java

Why the two html elements not aligned to each other after adding CSS?

From Dev

Adding comma after each two digits in String.Format

From Dev

Adding comma after each two digits in String.Format

From Dev

Java: Adding two random array elements for each category of a custom arraylist

From Dev

Adding 0's to cell array such that each column contains an equal number of entries - MATLAB

From Dev

Need to check to see if UITextField contains two (and only two) Strings of minimum 2 characters each in iOS

From Dev

haskell, map two lists adding each element of one with each of the other list

From Dev

Adding two Buttons dynamically in UITableViewCell at last cells after displaying JSON value on each cell

From Dev

Comparing two dataframes of different length row by row and adding columns for each row with equal value

From Dev

Adding two lines for each category in horizontal axis scatterplot(ggplot2)

From Dev

Django - Looping through two queries for the same data, and adding cost field for each

From Dev

Adding two arrays to each other where the first value of the array is added to the first value of the second array 100 times?

From Dev

Adding a string to iteslf in an $.each

From Dev

Adding an eventListener to each checkbox

From Dev

if contains two words

From Dev

If string contains two characters

From Dev

Contains on two values?

From Dev

Adding two LPCWSTR variables

From Dev

Adding two vectors by names

From Dev

Adding two images PHP

From Dev

Adding two strings mathematically?

From Dev

Adding two Binding in WPF

From Dev

Adding Two Objects?

From Dev

Adding two shadows to a UILabel

From Dev

Adding two lists

From Dev

Adding two submatrices in Matlab?

From Dev

adding two fractions in python

Related Related

  1. 1

    Adding two contains for a .each()

  2. 2

    Adding two tuples and applying a function to each element

  3. 3

    Why the two html elements not aligned to each other after adding CSS?

  4. 4

    Adding comma after each two digits in String.Format

  5. 5

    Adding comma after each two digits in String.Format

  6. 6

    Java: Adding two random array elements for each category of a custom arraylist

  7. 7

    Adding 0's to cell array such that each column contains an equal number of entries - MATLAB

  8. 8

    Need to check to see if UITextField contains two (and only two) Strings of minimum 2 characters each in iOS

  9. 9

    haskell, map two lists adding each element of one with each of the other list

  10. 10

    Adding two Buttons dynamically in UITableViewCell at last cells after displaying JSON value on each cell

  11. 11

    Comparing two dataframes of different length row by row and adding columns for each row with equal value

  12. 12

    Adding two lines for each category in horizontal axis scatterplot(ggplot2)

  13. 13

    Django - Looping through two queries for the same data, and adding cost field for each

  14. 14

    Adding two arrays to each other where the first value of the array is added to the first value of the second array 100 times?

  15. 15

    Adding a string to iteslf in an $.each

  16. 16

    Adding an eventListener to each checkbox

  17. 17

    if contains two words

  18. 18

    If string contains two characters

  19. 19

    Contains on two values?

  20. 20

    Adding two LPCWSTR variables

  21. 21

    Adding two vectors by names

  22. 22

    Adding two images PHP

  23. 23

    Adding two strings mathematically?

  24. 24

    Adding two Binding in WPF

  25. 25

    Adding Two Objects?

  26. 26

    Adding two shadows to a UILabel

  27. 27

    Adding two lists

  28. 28

    Adding two submatrices in Matlab?

  29. 29

    adding two fractions in python

HotTag

Archive