Jquery Session & Table Filtering

Posted by Bry4n on Stack Overflow See other posts from Stack Overflow or by Bry4n
Published on 2010-05-03T15:22:32Z Indexed on 2010/05/03 15:28 UTC
Read the original article Hit count: 335

Filed under:
|
|
|

This is my Jquery

     <script type="text/javascript">  
 $(function() {
 var from = $.session("from");
var to = $.session("to");

var $th = $('#theTable').find('th');
// had to add the classes here to not grab the "td" inside those tables
var $td = $('#theTable').find('td.bluedata,td.yellowdata');

 $th.hide();
 $td.hide();

if (to == "Select" || from == "Select") {
  // shortcut - nothing set, show everything
  $th.add($td).show();
  return;
}

 var filterArray = new Array();
filterArray[0] = to;
 filterArray[1] = from;

  $.each(filterArray, function(i){
    if (filterArray[i].toString() == "Select")
    {
        filterArray[i] = "";
    }
});   
$($th).each(function(){
    if ($( this,":eq(0):contains('" + filterArray[0].toString() + "')") != null
        && $(this,":eq(1):contains('" + filterArray[1].toString() + "')") != null)
    {
        $(this).show();
    }
});
 $($td).each(function(){
    if ($( this,":eq(0):contains('" + filterArray[0].toString() + "')") != null
        && $(this,":eq(1):contains('" + filterArray[1].toString() + "')") != null)
    {
        $(this).show();
    }
}); 
  });
  </script>

This is my table

 <table border="1" id="theTable">
    <tr class="headers">
        <th class="bluedata"height="20px" valign="top">63rd St. &amp; Malvern Av. Loop<BR/></th>
        <th class="yellowdata"height="20px" valign="top">52nd St. &amp; Lansdowne Av.<BR/></th>
        <th class="bluedata"height="20px" valign="top">Lancaster &amp; Girard Avs<BR/></th>
        <th class="yellowdata"height="20px" valign="top">40th St. &amp; Lancaster Av.<BR/></th>
        <th class="bluedata"height="20px" valign="top">36th &amp; Market Sts<BR/></th>
            <th class="bluedata"height="20px" valign="top">6th &amp; Market Sts<BR/></th>
        <th class="yellowdata"height="20px" valign="top">Juniper Station<BR/></th>
    </tr>
    <tr>
        <td class="bluedata"height="20px" title="63rd St. &amp; Malvern Av. Loop">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
        <td class="yellowdata"height="20px" title="52nd St. &amp; Lansdowne Av.">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
         <td class="bluedata"height="20px" title="Lancaster &amp; Girard Avs">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
         </td>
        <td class="yellowdata"height="20px" title="40th St. &amp; Lancaster Av.">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
        <td class="bluedata"height="20px" title="36th &amp; Market Sts">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
            <td class="bluedata"height="20px" title="6th &amp; Market Sts">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
        <td class="bluedata"height="20px" title="Juniper Station">
        <table width="100%"><tr><td>12:17am</td></tr><tr><td>12:17am</td></tr><tr><td>12:47am</td></tr></table>
        </td>
    </tr>
</table>

I have asked questions on here before and I have had success in converting textbox values to dropdown changes. However this is a bit different. I am using the sessions plugin (which works fine). On one page I have a set of normal drop downs, on submit you get taken to a separate page which runs the function above, however the rows/columns all show and they don't seem to filter at all.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html