<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Book Excerpt - Table Manipulation</title>
	<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation</link>
	<description>Getting to know the library of choice for unobtrusive JavaScript</description>
	<pubDate>Fri, 29 Aug 2008 00:10:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Matthew</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-53224</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Thu, 14 Aug 2008 21:32:59 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-53224</guid>
		<description>Hey guys,

I am trying to do what Corrado Fiore  is doing above, but I would love to see an example with dropdowns instead of div tags to filter.

Ive copied Corrado's code and used the example table, but it doesnt filter or do anything for me.  

Thank you,

Matthew</description>
		<content:encoded><![CDATA[<p>Hey guys,</p>
<p>I am trying to do what Corrado Fiore  is doing above, but I would love to see an example with dropdowns instead of div tags to filter.</p>
<p>Ive copied Corrado&#8217;s code and used the example table, but it doesnt filter or do anything for me.  </p>
<p>Thank you,</p>
<p>Matthew</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-22996</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Mon, 03 Dec 2007 19:01:28 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-22996</guid>
		<description>Hi Corrado, 

I'm so glad you like the book! To keep filtering, try replacing these lines ...

&lt;pre&gt;&lt;code&gt;              if ($('td', this).filter(':nth-child(' + (column + 1) + ')').text() == event.data['keyword']) {
                $(this).removeClass('filtered').not('.collapsed').show();
              }
              else if ($('th',this).length == 0) {
                $(this).addClass('filtered').hide();
              }&lt;/code&gt;&lt;/pre&gt;

with these ...

&lt;pre&gt;&lt;code&gt;              if ($('th',this).length == 0) {
                $(this).addClass('filtered').hide();
              }&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi Corrado, </p>
<p>I&#8217;m so glad you like the book! To keep filtering, try replacing these lines &#8230;</p>
<pre><code>              if ($('td', this).filter(':nth-child(' + (column + 1) + ')').text() == event.data['keyword']) {
                $(this).removeClass('filtered').not('.collapsed').show();
              }
              else if ($('th',this).length == 0) {
                $(this).addClass('filtered').hide();
              }</code></pre>
<p>with these &#8230;</p>
<pre><code>              if ($('th',this).length == 0) {
                $(this).addClass('filtered').hide();
              }</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Corrado Fiore</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-22981</link>
		<dc:creator>Corrado Fiore</dc:creator>
		<pubDate>Mon, 03 Dec 2007 17:02:56 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-22981</guid>
		<description>Hi,

justed want to say "Thanks!" for such an invaluable book.  I'm one of the many developers to whom Jquery (and your book) opened the doors of rich client scripting.

That said, I have a little question about table filtering.  I was able to set up filtering for my table using some &#60;select&#62;, using the following code:

&lt;pre&gt;&lt;code&gt;$(document).ready(function() {
  $('table.filterable').each(function() {
    var $table = $(this);
    $table.find('th').each(function (column) {
      if ($(this).is('.filter-column')) {
        var $filters = $('&#60;select class="filters"&#62; ' + $(this).text() + ' &#60;/select&#62;');
        var keywords = {};
        $table.find('tbody tr td').filter(':nth-child(' + (column + 1) + ')').each(function() {
          keywords[$(this).text()] = $(this).text();
        })

        $('&#60;option class="filter"&#62;All&#60;/option&#62;').click(function() {
          $table.find('tbody tr').removeClass('filtered').not('.collapsed').show();
          $(this).addClass('active').siblings().removeClass('active');
          $table.trigger('stripe');
        }).addClass('clickable active').appendTo($filters);
        $.each(keywords, function (index, keyword) {
          $('&#60;option class="filter"&#62;&#60;/option&#62;').text(keyword).bind('click',
                              {'keyword': keyword}, function(event) {
            $table.find('tbody tr').each(function() {
              if ($('td', this).filter(':nth-child(' + (column + 1) + ')').text() == event.data['keyword']) {
                $(this).removeClass('filtered').not('.collapsed').show();
              }
              else if ($('th',this).length == 0) {
                $(this).addClass('filtered').hide();
              }
            });
            $(this).addClass('active').siblings().removeClass('active');
            $table.trigger('stripe');
          }).addClass('clickable').appendTo($filters);
        });
        $filters.insertBefore($table);
      }
    });
  });
  	// This ensures that the first option of each select remains visible
  	$("select.filters").each(function() {
  		$(":first-child").attr({ selected: "selected" })
	});
});&lt;/code&gt;&lt;/pre&gt;

The above code will generate a &#60;select&#62; for each column marked as filterable.  But, as soon as another select gets clicked, the previous filtering will be "forgotten" by the script.  In other words, only the last clicked select is considered.

Now, I wish to push filtering a step further, i.e. combining multiple filters.  The user should be able to filter rows using one select and then refine his/her search using other ones.

Any advice will be appreciated.

Thanks,
Corrado Fiore</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>justed want to say &#8220;Thanks!&#8221; for such an invaluable book.  I&#8217;m one of the many developers to whom Jquery (and your book) opened the doors of rich client scripting.</p>
<p>That said, I have a little question about table filtering.  I was able to set up filtering for my table using some &lt;select&gt;, using the following code:</p>
<pre><code>$(document).ready(function() {
  $('table.filterable').each(function() {
    var $table = $(this);
    $table.find('th').each(function (column) {
      if ($(this).is('.filter-column')) {
        var $filters = $('&lt;select class="filters"&gt; ' + $(this).text() + ' &lt;/select&gt;');
        var keywords = {};
        $table.find('tbody tr td').filter(':nth-child(' + (column + 1) + ')').each(function() {
          keywords[$(this).text()] = $(this).text();
        })

        $('&lt;option class="filter"&gt;All&lt;/option&gt;').click(function() {
          $table.find('tbody tr').removeClass('filtered').not('.collapsed').show();
          $(this).addClass('active').siblings().removeClass('active');
          $table.trigger('stripe');
        }).addClass('clickable active').appendTo($filters);
        $.each(keywords, function (index, keyword) {
          $('&lt;option class="filter"&gt;&lt;/option&gt;').text(keyword).bind('click',
                              {'keyword': keyword}, function(event) {
            $table.find('tbody tr').each(function() {
              if ($('td', this).filter(':nth-child(' + (column + 1) + ')').text() == event.data['keyword']) {
                $(this).removeClass('filtered').not('.collapsed').show();
              }
              else if ($('th',this).length == 0) {
                $(this).addClass('filtered').hide();
              }
            });
            $(this).addClass('active').siblings().removeClass('active');
            $table.trigger('stripe');
          }).addClass('clickable').appendTo($filters);
        });
        $filters.insertBefore($table);
      }
    });
  });
  	// This ensures that the first option of each select remains visible
  	$("select.filters").each(function() {
  		$(":first-child").attr({ selected: "selected" })
	});
});</code></pre>
<p>The above code will generate a &lt;select&gt; for each column marked as filterable.  But, as soon as another select gets clicked, the previous filtering will be &#8220;forgotten&#8221; by the script.  In other words, only the last clicked select is considered.</p>
<p>Now, I wish to push filtering a step further, i.e. combining multiple filters.  The user should be able to filter rows using one select and then refine his/her search using other ones.</p>
<p>Any advice will be appreciated.</p>
<p>Thanks,<br />
Corrado Fiore</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: teresa hurley</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-19547</link>
		<dc:creator>teresa hurley</dc:creator>
		<pubDate>Wed, 07 Nov 2007 20:13:42 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-19547</guid>
		<description>Hi Guys,

Thanks for a great book to help me learn jQuery! I've been out of the js loop for a few years, doing more administrative type stuff at my job... but lately I've been asked to get back into helping with actual coding. So I have a lot of catching up to do, and this is a great help.

I'm working through the book, and happen to be on this chapter. I'd like to submit a jQuery 1.2.1 problem and its fix as well as a Safari problem I just can't seem to get around.

First, the jQuery 1.2.1 problem/fix:

In the pagination code in tables.js, I was getting an error that &lt;code&gt;$table.find('tbody tr').show().lt()&lt;/code&gt; is not a function. After a bunch of searching, I found that  jQuery 1.2 doesn't support &lt;code&gt;.lt()&lt;/code&gt; or  &lt;code&gt;.gt()&lt;/code&gt; anymore. We now must use  &lt;code&gt;.slice(0, n)&lt;/code&gt; in place of  &lt;code&gt;.lt()&lt;/code&gt; and  &lt;code&gt;.slice(n+1)&lt;/code&gt; in place of  &lt;code&gt;.gt()&lt;/code&gt;, thus:
&lt;code&gt;$(document).ready(function()
{
	$('table.paginated').each(function()
	{
		var currentPage = 0;
		var numPerPage = 10;
		var $table = $(this);
		$table.bind('repaginate',
		 	function()
			{
		    	$table
					.find('tbody tr')
					.show()
					//lt was removed from jquery, use slice instead
			                    //.lt(currentPage * numPerPage)
					//new syntax:
					.slice(0, currentPage * numPerPage)
			          .hide()
			        .end()
					//gt was removed from jquery, use slice instead
			                    //.gt((currentPage + 1) * numPerPage - 1)
					//new syntax:
					.slice((currentPage + 1) * numPerPage - 1)
			          .hide()
			        .end();			
			});
//...code continues&lt;/code&gt;
Hopefully, that'll help anyone else new and struggling as I am.

Now for my Safari vs. collapsing table rows problem.

I'm using Safari 2.0.4. It appears that "opacity" is not a property of &#60;tr&#62; (or thead, tbody, tfoot, for that matter). So the collapse code just makes the rows disappear, but not fade out prettily. Then, when I un-collapse, the spacing is all messed up: too much space between table rows, table row height shrinking, etc. Using hide/show instead of fadeOut/fadeIn works as expected (w/o the fade effect, obviously, but also with no funkiness w/regard to spacing).

The most recent thing I tried was to fade out the table cells instead of the rows. The first fade out appears to work fine. Fade in, however, does not: it seems to actually add table cells to each row (and they don't fade, in, they just appear). Then, subsequent fade outs are flaky: the rows are not completely absent. This also breaks firefox on the fade out, in that it leaves a space between the &#60;th&#62; row above and below the collapsed rows. Example here: http://hurleyhouse.com/learning_jquery/chapter_7/news/

I've searched and searched, and haven't been able to find anyone else having the problem... Am I alone? Does anyone know of a workaround? Or is it possible I've just done something completely wrong here?
&lt;code&gt;$(document).ready(function()
{
	var toggleMinus = '../icons/bullet_toggle_minus.png';
	var togglePlus = '../icons/bullet_toggle_plus.png';
	var $subHead = $('tbody th:first-child');
	$subHead.prepend('&#60;img src="'+toggleMinus+'" alt="collapse this section" /&#62;');
	$('img', $subHead)
		.addClass('clickable')
		.click(function()
		{
			var toggleSrc = $(this).attr('src');
			if (toggleSrc == toggleMinus)
			{
				$(this)
				.attr('src', togglePlus)
				.parents('tr')
				.siblings()
				.addClass('collapsed')
			//	.hide(); //works fine in safari
				
				.children() //need this for next to work in safari, because safari doesn't allow tr opacity
					      /*
                                              problem is, it leaves a big space in firefox (mac, anyway) also fadein is broken
						      see fadein note below
					      */
				.fadeOut('slow');
			}
			else
			{
				$(this)
				.attr('src', toggleMinus)
				.parents('tr')
				.siblings()
				.not('.filtered')
				.removeClass('collapsed')
			//	.show(); //works fine in safari, when hide is used above
				
				/*
                               the following totally breaks in safari... each time it's called, it adds more table cells
				    first, it's  one td for each existing td, then subsequent, it's one less than the original
				    number of tds... so you have four at first, then eight, then eleven, then fourteen, etc.
                          */
				.children()
				.fadeIn('slow');
			}
		});
});&lt;/code&gt;

thanks so much!
tree</description>
		<content:encoded><![CDATA[<p>Hi Guys,</p>
<p>Thanks for a great book to help me learn jQuery! I&#8217;ve been out of the js loop for a few years, doing more administrative type stuff at my job&#8230; but lately I&#8217;ve been asked to get back into helping with actual coding. So I have a lot of catching up to do, and this is a great help.</p>
<p>I&#8217;m working through the book, and happen to be on this chapter. I&#8217;d like to submit a jQuery 1.2.1 problem and its fix as well as a Safari problem I just can&#8217;t seem to get around.</p>
<p>First, the jQuery 1.2.1 problem/fix:</p>
<p>In the pagination code in tables.js, I was getting an error that <code>$table.find('tbody tr').show().lt()</code> is not a function. After a bunch of searching, I found that  jQuery 1.2 doesn&#8217;t support <code>.lt()</code> or  <code>.gt()</code> anymore. We now must use  <code>.slice(0, n)</code> in place of  <code>.lt()</code> and  <code>.slice(n+1)</code> in place of  <code>.gt()</code>, thus:<br />
<code>$(document).ready(function()<br />
{<br />
	$('table.paginated').each(function()<br />
	{<br />
		var currentPage = 0;<br />
		var numPerPage = 10;<br />
		var $table = $(this);<br />
		$table.bind('repaginate',<br />
		 	function()<br />
			{<br />
		    	$table<br />
					.find('tbody tr')<br />
					.show()<br />
					//lt was removed from jquery, use slice instead<br />
			                    //.lt(currentPage * numPerPage)<br />
					//new syntax:<br />
					.slice(0, currentPage * numPerPage)<br />
			          .hide()<br />
			        .end()<br />
					//gt was removed from jquery, use slice instead<br />
			                    //.gt((currentPage + 1) * numPerPage - 1)<br />
					//new syntax:<br />
					.slice((currentPage + 1) * numPerPage - 1)<br />
			          .hide()<br />
			        .end();<br />
			});<br />
//...code continues</code><br />
Hopefully, that&#8217;ll help anyone else new and struggling as I am.</p>
<p>Now for my Safari vs. collapsing table rows problem.</p>
<p>I&#8217;m using Safari 2.0.4. It appears that &#8220;opacity&#8221; is not a property of &lt;tr&gt; (or thead, tbody, tfoot, for that matter). So the collapse code just makes the rows disappear, but not fade out prettily. Then, when I un-collapse, the spacing is all messed up: too much space between table rows, table row height shrinking, etc. Using hide/show instead of fadeOut/fadeIn works as expected (w/o the fade effect, obviously, but also with no funkiness w/regard to spacing).</p>
<p>The most recent thing I tried was to fade out the table cells instead of the rows. The first fade out appears to work fine. Fade in, however, does not: it seems to actually add table cells to each row (and they don&#8217;t fade, in, they just appear). Then, subsequent fade outs are flaky: the rows are not completely absent. This also breaks firefox on the fade out, in that it leaves a space between the &lt;th&gt; row above and below the collapsed rows. Example here: <a href="http://hurleyhouse.com/learning_jquery/chapter_7/news/" rel="nofollow">http://hurleyhouse.com/learning_jquery/chapter_7/news/</a></p>
<p>I&#8217;ve searched and searched, and haven&#8217;t been able to find anyone else having the problem&#8230; Am I alone? Does anyone know of a workaround? Or is it possible I&#8217;ve just done something completely wrong here?<br />
<code>$(document).ready(function()<br />
{<br />
	var toggleMinus = '../icons/bullet_toggle_minus.png';<br />
	var togglePlus = '../icons/bullet_toggle_plus.png';<br />
	var $subHead = $('tbody th:first-child');<br />
	$subHead.prepend('&lt;img src="'+toggleMinus+'" alt="collapse this section" /&gt;');<br />
	$('img', $subHead)<br />
		.addClass('clickable')<br />
		.click(function()<br />
		{<br />
			var toggleSrc = $(this).attr('src');<br />
			if (toggleSrc == toggleMinus)<br />
			{<br />
				$(this)<br />
				.attr('src', togglePlus)<br />
				.parents('tr')<br />
				.siblings()<br />
				.addClass('collapsed')<br />
			//	.hide(); //works fine in safari</p>
<p>				.children() //need this for next to work in safari, because safari doesn't allow tr opacity<br />
					      /*<br />
                                              problem is, it leaves a big space in firefox (mac, anyway) also fadein is broken<br />
						      see fadein note below<br />
					      */<br />
				.fadeOut('slow');<br />
			}<br />
			else<br />
			{<br />
				$(this)<br />
				.attr('src', toggleMinus)<br />
				.parents('tr')<br />
				.siblings()<br />
				.not('.filtered')<br />
				.removeClass('collapsed')<br />
			//	.show(); //works fine in safari, when hide is used above</p>
<p>				/*<br />
                               the following totally breaks in safari... each time it's called, it adds more table cells<br />
				    first, it's  one td for each existing td, then subsequent, it's one less than the original<br />
				    number of tds... so you have four at first, then eight, then eleven, then fourteen, etc.<br />
                          */<br />
				.children()<br />
				.fadeIn('slow');<br />
			}<br />
		});<br />
});</code></p>
<p>thanks so much!<br />
tree</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-15892</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Thu, 11 Oct 2007 22:23:58 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-15892</guid>
		<description>Hi Joe, 

The &lt;code&gt;.is()&lt;/code&gt; method is not xpath. Is the period after "is" in your code above a typo? It shouldn't be there. We have a &lt;a href="http://book.learningjquery.com/bookstore/books/" rel="nofollow"&gt;working demo&lt;/a&gt; that you might want to look at for comparison.</description>
		<content:encoded><![CDATA[<p>Hi Joe, </p>
<p>The <code>.is()</code> method is not xpath. Is the period after &#8220;is&#8221; in your code above a typo? It shouldn&#8217;t be there. We have a <a href="http://book.learningjquery.com/bookstore/books/" rel="nofollow">working demo</a> that you might want to look at for comparison.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-15628</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Tue, 09 Oct 2007 22:18:30 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-15628</guid>
		<description>Interesting - so far I'm doing well with the book, but got my first real stumper on the next line of the same script:

&lt;code&gt;
if ($(this).is.('.sortAlpha'))	{
&lt;/code&gt;

where I get a "XML filtering predicate operator called on incompatible Function" error in Firebug.

is .is xpath?</description>
		<content:encoded><![CDATA[<p>Interesting - so far I&#8217;m doing well with the book, but got my first real stumper on the next line of the same script:</p>
<p><code><br />
if ($(this).is.('.sortAlpha'))	{<br />
</code></p>
<p>where I get a &#8220;XML filtering predicate operator called on incompatible Function&#8221; error in Firebug.</p>
<p>is .is xpath?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-14954</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Wed, 03 Oct 2007 22:57:32 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-14954</guid>
		<description>Hi Scott,
It's possible that you haven't included enough code. Whenever we store a jQuery object as a variable, we precede the variable with "$". It could be that you don't have the &lt;code&gt;$table&lt;/code&gt; variable defined anywhere. Without looking back at the code, I think we had something like &lt;code&gt;var $table = $(this);&lt;/code&gt;.

The only reason it might fail in 1.2.1 as opposed to an earlier version is if we used an XPath selector there, but that doesn't seem to be the case.

Hope that helps.</description>
		<content:encoded><![CDATA[<p>Hi Scott,<br />
It&#8217;s possible that you haven&#8217;t included enough code. Whenever we store a jQuery object as a variable, we precede the variable with &#8220;$&#8221;. It could be that you don&#8217;t have the <code>$table</code> variable defined anywhere. Without looking back at the code, I think we had something like <code>var $table = $(this);</code>.</p>
<p>The only reason it might fail in 1.2.1 as opposed to an earlier version is if we used an XPath selector there, but that doesn&#8217;t seem to be the case.</p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ScottDavis</title>
		<link>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-14953</link>
		<dc:creator>ScottDavis</dc:creator>
		<pubDate>Wed, 03 Oct 2007 21:29:33 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/08/book-excerpt-table-manipulation#comment-14953</guid>
		<description>Any chance this doesn't run "out of the box" against jQuery 1.2.1? I'm getting error "$table.find("tbody tr").show().lt is not a function" on line 85 of table.js, but not if I run against your copy of jquery.js. Perhaps I haven't included enough code...</description>
		<content:encoded><![CDATA[<p>Any chance this doesn&#8217;t run &#8220;out of the box&#8221; against jQuery 1.2.1? I&#8217;m getting error &#8220;$table.find(&#8221;tbody tr&#8221;).show().lt is not a function&#8221; on line 85 of table.js, but not if I run against your copy of jquery.js. Perhaps I haven&#8217;t included enough code&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
