Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery tablesorter: custom html image tag sorter/parser
    primarykey
    data
    text
    <p>I am using the <a href="http://tablesorter.com" rel="nofollow">jQuery tablesorter plugin</a>. It seems to be working fine except that it can't sort rows with image tags as their content. I want to implement something that just sorts by the src attribute of the image tag. I have tried a number of things but can't seem to get it to work.</p> <h2>Problems:</h2> <ul> <li>The plugin does not detect my image columns with the image parser, it detects it as using the <code>digit</code> parser, so I have to specify the image parser manually.</li> <li>The <code>s</code> argument being passed to the <code>format</code> function of my parser seems to be blank/null/undefined (something like that, I can't tell).</li> </ul> <h2>Code:</h2> <p>JavaScript:</p> <pre><code>$.tablesorter.addParser({ id: 'image', is: function(s) { //i think this works return /^&lt;img(.*)&gt;$/.test(s); }, format: function(s) { //neither of these work return $(s).attr('src').toLowerCase(); return s.match(/src="(.*)"/); }, type: 'text' }); $(document).ready(function() { $("table").tablesorter(); }); </code></pre> <p>HTML:</p> <pre><code>&lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;text column&lt;/th&gt; &lt;th class="{sorter: 'image'}"&gt;image column&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;a&lt;/td&gt; &lt;td&gt;&lt;img src="d.gif"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;b&lt;/td&gt; &lt;td&gt;&lt;img src="c.gif"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;c&lt;/td&gt; &lt;td&gt;&lt;img src="b.gif"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;d&lt;/td&gt; &lt;td&gt;&lt;img src="a.gif"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload