javascript - jQuery filter table with multi select -
i'm trying filter table filters. simple selects, , others multiples. simple ones, that's ok, not multiple.
i want follow logic :
- passing through array contains filter (
filtre_transports) - passing through array contains value(s) (
ligne_transports) - if element of 1. isn't in 2. not display line (
transports_matches = false)
i made code :
// pass through each line of table jquery('#agents_liste tbody tr').not('.vide').each(function() { var transports_matches = true; // ligne_transports array contains values compare filter var ligne_transports = jquery(this).children('td').eq(2).text().split('###'); // filtre_transports array contains selected val of multi select jquery(filtre_transports).each(function() { var filtre = jquery(this); var filtreok = false; jquery(ligne_transports).each(function() { if (filtre == jquery(this)) { filtreok = true; return false; } }); if (!filtreok) { transports_matches = false; return false; } }); }); the problem : when have filters selected, result transports_matches false.
btw, saw this post answer use classes, there way without them ?
edit : can see jsfiddle here.
thanks
fixed: http://jsfiddle.net/r4mfv/2/
you had couple of issues:
$(filtre_transports).eachnot way iterate on array, should use$.each(filtre_transports, function() {...}).you should cast
filtre,thisstringbefore comparing them.
Comments
Post a Comment