RussellHarrower RussellHarrower - 7 months ago 65
jQuery Question

jQuery wont allow me to sort table

I am trying to sort a table but I am calling the table from a function and it seems that the table.js which is using this js

I thought I would try to call that js file when the function gets called, but that did not work. so I included it in the index.php page to hopefully get it to work.

But when the function runs, it seems that it does not like that the table was not called from the very beginning of the


The function is below.

function listallleads(){
$("#menuarea").html('<table class="sortable paginated"><thead><tr><th class="sort-alpha"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Column 1</th></tr></thead><tbody><tr><td>Field 1</td></tr><tr><td>Field 3</td></tr><tr><td>Field 2</td></tr></tbody></table>');


The plug-in you're using is hard-coded to apply the sortable functions at document ready time. You've got two options:

  1. Modify the library to have an init function instead of (or in addition to) using document.ready and call it accordingly. Really, that would be a better architecture, but you may not want to start hacking away on the library, particularly if it's being used elsewhere on your site.
  2. Instead of injecting the html into menuarea, have the table in a hidden div from the start, and make the button toggle its visibility.

Hope that helps.