English 中文(简体)
Jquery TableSorter 2.0 - Revert Sort order
原标题:

All,

I am using the JQuery TableSorter Plugin. The table sorts fine for the selected columns. Consider that when the page loads, there is no sorting taking place. Now, if the table is sorted by one column, it sorts. Now, upon clicking a "Revert Sort" link outside the table, the tablesorter should revert to the initial sort order, even if it sorted multiple coumns before. How can we achieve this?

Thanks

问题回答

So by "there is no sorting taking place" you mean you just do

$("#myTable").tablesorter();

And after a click on a link you want the table to look like just after this call with no sorting done?

I don t think there is an easy way to do this. But I provide a hack how this could be done, but beware depending on the size of your table this might use up a good amount of browser memory.

The idea is to copy the table before you apply the tablesorter plugin. Later when clicking the link just restore the table as it was and reapply tablesorter. e.g.

var tablebackup;
$(document).ready(function() {
  tablebackup = $("#myTable").clone();
  $("#myTable").tablesorter();
});

function resetTable() {
  tablebackup.clone().insertAfter("#myTable");
  $("#myTable").remove();
  $("#myTable").tablesorter();
}

Check this for a full working example http://jsbin.com/ujiko (no css or anything but works)

Thanks a bunch.. It Works like a charm if there s one table on the page. If I have nested tabs with a table in each, this seems to work only for the table in the last tab.

Following is the PHP code I have to generate this JS on fly when nested JQuery UI tabs are generated:

                echo  <script type="text/javascript"> ;
                echo  function resetTable() { ;
                echo  tablebackup.clone().insertAfter("#table .$i. "); ;
                echo  $("#table .$i. ").remove(); ;
                echo  $("#table .$i. ").tablesorter({widthFixed: true, widgets: [ zebra ]})
                      .tablesorterPager({container: $("#pager .$i. ")}); ;
                echo  } ;

                echo  $(document).ready(function() { ;
                echo "$( #fragment-2 ).tabs();";
                echo  tablebackup = $("#table .$i. ").clone(); ;
                echo  $("#table .$i. ").tablesorter({widthFixed: true, widgets: [ zebra ]})
                      .tablesorterPager({container: $("#pager .$i. ")}); ;                    
                echo "});";
                echo "</script>";

Any ideas on fixing this?

Thanks





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签