Home >
Article > Web Front-end > JavaScript is extremely fast. It only takes 60 milliseconds to hide/show table columns with 10,000 rows_javascript skills
JavaScript is extremely fast. It only takes 60 milliseconds to hide/show table columns with 10,000 rows_javascript skills
WBOYOriginal
2016-05-16 18:54:461241browse
The most common way to hide table columns is as follows:
This method is extremely inefficient. For example, hiding a column of a thousand-row table takes about 4000 milliseconds to execute on my laptop (P4 M 1.4G, 768M memory), which is unbearable. For example, the following code:
Unfortunately, we use javascript to hide columns from Google The method is to use such code. In fact, we can quickly hide columns by setting the width of the first row's td or th to 0. We change the hideOrShowCol() function to the following code:
Retesting, we found that it only takes less than 15 milliseconds to hide a column of a thousand-row table. Even if you use createTable(10000) to create a table with 10,000 rows, and then test it, it only takes 60 milliseconds (all based on the execution time on my laptop. In fact, most of your computer configurations are better than mine) The notebook is much taller, so the time will be shorter), and the efficiency is very satisfactory. Supplement: According to the suggestion of Wu Chang netizen, the code for colgroup processing has been added. The strange thing is that although the processing principle is exactly the same, the time to process colgroup reaches 140 milliseconds, which is doubled. It's unclear why. Full code:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn