0

I was looking at the usage of jquery filter for data attributes, in this case, tables containing three data variables, i.e, team, specialization and level. Please do let me know what the best approach is and what the typical usage methodology are. Here is my code html:

<table data-team="<?php print $name['team']; ?>" data-specialization="<?php print $name['speciality']; ?>" data-level="<?php print $name['level']; ?>" cellpadding="0" cellspacing="0" border="0" width="670px" class="jobs"><tr><td>
            <tr><td colspan="4"><strong><?php print $name['title'] ?></strong></td>
            <td></td><td></td><td></td></tr>
            <tr>
            <td width="100">Location : </td>
            <td colspan="3"><?php print ($name['location']);?> </td>
            <td></td>
            <td></td>
            <td></td>
            </tr>
            <tr>
            <td> Job Code : </td>
            <td width="460"><?php print $name['id'] ?></td>
            <td></td>
            <td></td> 
            <td><a data-action="showDesc,jumpTo" href="javascript:;" id="<?php print($name['id']);?>" class="more">More Details </a></td>
            </tr></td></tr>
        </table>

The javascript that I have I got from one other Stack Overflow question, and it works on showing based on one matching attribute, here is my code:

$("#search").click(function() {
            var team=$('#selectOne').val();
            var specialty=$('#selectTwo').val();
            var level=$('#selectThree').val();
            var teams=[];// 
            var special=[];
            var level=[];
            //teams=$('.jobs').data('team');
            //alert(teams);

                    $(".jobs").hide();
                        $('.jobs').filter(function(){
                                    return $(this).data('team') === team;
                                }).show();
                            });
   });

I want to put all the data-team attributes into the array, iterate over it and then check if each table contains it, in which case to the next array, to check and so on. if the data values match then, show.

1
  • Turns out my error was that I reassigned the levels variable to an array thereby emptying it, it works just fine now. Thanks
    – Ego
    Jan 9, 2013 at 7:48

1 Answer 1

0

Turns out my error was just that I re-declared the variables team[]. so basically, this:

$('.jobs')  .hide().filter('[data-team="'+team+'"][data-specialization="'+specialty+'"][data-level="'+level+'"]').addClass('num').show();

Works fine now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.