开发者

Jquery XML Data Sorting By Date

I have some XML which I am reading by jQuery and printing on screen.

This is XML

<users>
   <user>
      <id>1</id>
      <fname>Umair</fname>
      <timestamp>2011-03-18T03:41:00-07:00&开发者_开发知识库lt;/timestamp>
   </user>
   <user>
      <id>2</id>
      <fname>Neil</fname>
      <timestamp>2011-03-18T03:41:00-07:00</timestamp>
   </user>
</users>

This is JS

$(xml).find("user").each(function(index, user) {
   var timestamp = $(user).children("date_time:first").text();
   //the dt has date and time in such format 2011-03-18T03:41:00-07:00
   //more code which generates below html and add to the userTable
   //<tr>
   //   <td>
   //      <div>First Name</div>
   //      <div>2011-03-18T03:41:00-07:00</div>
   //   </td>
   //</tr>

   //$("#userTable").append(...all rows here...); 
});

This is HTML

<table id="userTable">

<table>

This is working perfect though the only thing I want to do is sorting this list of users when shown through HTML table. Is there a jQuery plugin I can use or any way around?


jQuery tablesorter will do the trick.


There is a jQuery plugin called $.timeago which did the magic.


It is fairly simple to sort by dates using the Date object. See a similar example I put together using the Date object and a neat use of BACKREFERENCES of the global RegExp object at:

http://jsfiddle.net/elusien/eZ3RQ/

You should be able to modify it to your purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜