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);
javascriptTable排序
最新推荐文章于 2024-01-09 17:33:58 发布
本文介绍了一种简单的表格排序方法,包括将待排序行放入tbody标签内、利用JavaScript将这些行存储为数组、根据需求对数组进行排序、使用文档碎片提高DOM操作效率以及最终将排序后的行重新插入表格中。
354

被折叠的 条评论
为什么被折叠?



