jquery - fastest way to remove all rows from a very large table

前端 未结 8 598
臣服心动
臣服心动 2021-01-30 09:40

I thought this might be a fast way to remove the contents of a very large table (3000 rows):

$jq(\"tbody\", myTable).remove();

But it\'s taking

8条回答
  •  盖世英雄少女心
    2021-01-30 10:24

    Two issues I can see here:

    1. The empty() and remove() methods of jQuery actually do quite a bit of work. See John Resig's JavaScript Function Call Profiling for why.

    2. The other thing is that for large amounts of tabular data you might consider a datagrid library such as the excellent DataTables to load your data on the fly from the server, increasing the number of network calls, but decreasing the size of those calls. I had a very complicated table with 1500 rows that got quite slow, changing to the new AJAX based table made this same data seem rather fast.

提交回复
热议问题