473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sorting large tables

1
The main problems are:
- adding rows to tables via appendChild is slow if there is markup in any cell. (My rows have only 3-8 cells)
- the same markup seems to increase the "lag" time to display, increasing further the apparent time to sort.

Some info:
I am trying to sort tables that may have thousands of rows. My sort works fine (acceptable) for < 500 rows. The actual speed (from click to sort, to final display) depends on what are in the TD cells. I found that if I have a SELECT node (or anything that adds markup) in a TD, it dramatically slows the building of the table.
My logic is:
- click on any column header. This sets the sort column and type (String,Number, etc)of compare function - no problem here.
- iterate through all the rows, collecting the selected column's value for the each row and associate the row with that value:
I create an array of associative arrays :
arr.push( { key: getCellValue(currentRow, col), row: currentRow } ).
then to sort I just compare the keys.
- sort this array. This is very fast - still no problem. I can sort any column just fine.
- iterate the newly ordered array, appending the rows to the TBODY of th table.

HERE IS THE PROBLEM
Even though I am just appending the rows to the TBODY, if a TD has any markup in it, the process is very slow. I am not in any way working with the cells during this process--I have a key and the row where the key came from, then I append by going through the sorted array.
I have noticed that there is a lag time from the time my code completes the sort process (sort and rebuilding DOM) before the browser displays. So the sort process can take, say, 500ms but the browser doesn't show any change for another 500 to 1000ms, for an overall appearance of 1-1.5 secs for a 500 row sort. (This is a "fast" example for 500 rows) If I use any markup in a TD the times increase to 4-5 secs, followed by the lag of another 4 to 5 secs. This makes it appear to take 10-12 secs to sort 500 rows! And I have to handle up to 10000. So far there is no way I can do it.


Any ideas or tips would be greatly appreciated.
Nov 30 '06 #1
4 5116
acoder
16,027 Expert Mod 8TB
The DOM methods may be slow - innerHTML may speed things up.

See the following for ideas:
http://www.kryogenix.org/code/browser/sorttable/
http://www.frequency-decoder.com/200...ript-revisited
http://www.workingwith.me.uk/article..._table_sorting
May 31 '08 #2
rnd me
427 Expert 256MB
in my experience, it is much faster to build a javascript array that you manipulate, then build/find a good and fast array to html table method.

i find that turning the array into a string of table code and using parent.innerHTML to be fastest.


further suggestions on table-making this way:
also use good html table coding techniques like <cols>, rows= attribs, tbody, and so on. (see w3schools).
this will reduce the parsing and rendering time of your strings.
set size positions where you can.
use css classes instead of long style attribs.
replace multiple dot variables with shorthand variables. this can vastly increase the speed of looped code.
eg: instead of: alert(a.b.c.d)
try something like var C=a.b.c; alert(C.d)
Jun 1 '08 #3
mrhoo
428 256MB
I would say that if you can sort and redraw a 500 row table onscreen in 1-1.5 seconds you are doing pretty well!

My only suggestion for a (shudder) 10000 row table is to draw a table with an initial tbody of, say, 100 rows, and a '...loading' message on the last row.

You can build another tbody offscreen with the remaining 9900 rows, or even in chunks of 500, and add the balance to the displayed table when it ready.

It might take longer than your original code, but there will be something to look at right away.
Jun 1 '08 #4
I faced a similar problem, so I wrote this project to tackle the problem of sorting a vast number of DOM element as quickly as the browser can render it: https://github.com/ngreen77/FastDomSorter
Oct 27 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: SASRS | last post by:
Here is my code. I am trying to see if I can put a %@ LANGUAGE="VBSCRIPT" %> <% FieldA = Request.QueryString("A") FieldB = Request.QueryString("B") FieldC = Request.QueryString("C") ...
17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
4
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
25
by: Dan Stromberg | last post by:
Hi folks. Python appears to have a good sort method, but when sorting array elements that are very large, and hence have very expensive compares, is there some sort of already-available sort...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
2
by: Simon | last post by:
Hi, I have a table I am populating with data from a DB, and have it sortable on the client side. When the table exceeds around 300 rows, I start running into problems with rendering and sorting...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.