您的位置:首页 > Web前端 > JavaScript

javascript Table排序

2009-12-27 17:23 423 查看
  

  基本步骤

  1,把需要排序的行放到tbody中(程序会直接取tbody的rows);

  2,把排序行放到一个数组中;

  this.Rows = Map(this.tBody.rows, function(o){ return o; });

  3,按需求对数组进行排序(用数组的sort方法);

  this.Rows.sort(Bind(this, this.Compare, orders, 0));

  4,用一个文档碎片(document.createDocumentFragment())保存排好序的行;

  var oFragment = document.createDocumentFragment();

  forEach(this.Rows, function(o){ oFragment.appendChild(o); });

  ps:文档碎片并不是必须的,但建议使用,大量dom操作时使用文档碎片会更有效率。

  5,把文档碎片插入到tbody中。

  this.tBody.appendChild(oFragment);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: