![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
I'm using javascript to construct large tables from an array of data, using ideas from: http://www.oreillynet.com/pub/a/java...nygoodman.html |
|
The data itself cannot be constructed by the javascript code, so is explicitly passed in with a large array, e.g. |
|
var data = new Array(); data.push(['name','phone','address','id','gender']) data.push(['john','555-5555','main st','123','m']) ... data.push(['sue','444-4444','park ave','456','f']) |
|
There may be several hundred to thousands of these entries. I was wondering if there's any way to compress the data as it's sent to the browser, so that javascript can unpack it to the original array. |
#3
| |||
| |||
|
|
kpmassey (AT) gmail (DOT) com wrote: I'm using javascript to construct large tables from an array of data, using ideas from: http://www.oreillynet.com/pub/a/java...nygoodman.html The article seems to assume that if you want to sort tables, you have to build them on the client. That's not so, most table sorts that I've seen use a table that is already in the page and just sort what's there, there's no need to create or delete any nodes at all. In regard to table creation, the article does not make any mention of DOM insertRow/Cell methods, which, if not faster than createElement, are at least more convenient to code. It also ignores cloneNode: it may be faster to clone an existing row and cells and modify the cell content than use either of the other methods. Therefore Mr. Goodman can only get half marks even if the rest of his article is perfect - which it isn't: e.g. for removing all the child nodes of an element, try replacing a node with a shallow clone of itself (can be buggy in some browsers). The data itself cannot be constructed by the javascript code, so is explicitly passed in with a large array, e.g. That is an incorrect assumption on Goodman's behalf that you have accepted: you get the original data from the original table, there is no need to pass it as a script variable. var data = new Array(); data.push(['name','phone','address','id','gender']) data.push(['john','555-5555','main st','123','m']) ... data.push(['sue','444-4444','park ave','456','f']) I didn't see anywhere that Goodman shows the array syntax, I'd have thought the best way is a literal: var data = [ ['name','phone','address','id','gender'], ['john','555-5555','main st','123','m'], ... ['sue','444-4444','park ave','456','f'] ]; If you want to take that further and have all the table attributes in an object, check out JSON: <URL: http://www.json.org/ There may be several hundred to thousands of these entries. I was wondering if there's any way to compress the data as it's sent to the browser, so that javascript can unpack it to the original array. There is no need if all you want to do is sort the table. Put the data in the page in an HTML table, use script to construct a data array at the client from the table (you only need the data from the column(s) to be sorted, not the entire table). After all, you only need the array if the user sorts the table. -- Fred |
#4
| |||
| |||
|
|
Fred, |
|
Thanks for your reply. I realize I could get the data from the html table, but that requires even more bandwidth because I have to include td class= ""> statements for every field in the table, |
|
and I've found it's actually easier programming to just create the table from scratch as Goodman describes. Now what I want to do is compress the data so that say, a 200 k file can be transmitted as a compressed, say 30k,chunk of data, and 2-3k of javascript code to reconstruct it. |
![]() |
| Thread Tools | |
| Display Modes | |
| |