473,409 Members | 2,006 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,409 software developers and data experts.

compress data for dynamic tables

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.

Any ideas much appreciated.
Thanks

Nov 6 '06 #1
3 2230
kp******@gmail.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

Nov 6 '06 #2
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.

Kenneth
Fred wrote:
kp******@gmail.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
Nov 6 '06 #3
kp******@gmail.com wrote:
Fred,
Please don't top-post here - reply below trimmed quotes.

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,
No you don't. How you identify the table(s) to be sorted is up to you,
it can be a single class attribute on the table itself. You don't have
to use someone else's sorting script, they are reasonably simple to
write.

In regard to bandwidth, the data is compressed on the wire anyway,
repeating character patterns (like element tags) are compressed very
efficiently. Write the same table as HTML and also as an array
literal, zip them and see how much you really save - it will give you a
rough idea.
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.
I would be very surprised if any browser could reconstruct a table from
an array faster than the equivalent HTML could be rendered, regardless
of how you do it. I can only imagine that you will use an embedded
document.write to do the HTML, any other technique will require you to
do it onload, which I think users will find very annoying.

If you want to cut down on bandwidth, drop closing </p></tdand </tr>
tags - they aren't needed in valid HTML 4.
--
Fred

Nov 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stefan Hinz | last post by:
Jim, >> Does MySQL automatically handle deleted row cleanup, or is it necessary to >> periodically do this manually for tables with a lot of deletions? If it's >> manual, what are the SQL...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
8
by: Jose L. Velazquez | last post by:
Hi all, I have made a webservice that returns an XML, but sometimes the connection is so slow and there is a lot of data to be returned. I would like to know if it is possible to send this data...
4
by: Harry Keck | last post by:
I have a dynamic xml file that needs to be downloaded periodically to the client from an ASP.Net application. This file can be rather large, but it zips up very small. Does anyone know of a...
7
by: Konstantin Andreev | last post by:
Well known, during "CREATE TABLE" we could optionally specify "COMPRESS SYSTEM DEFAULT" and "VALUE COMPRESSION" options. The main idea about these statements is : NOT to keep on disk the values that...
3
by: piscogirl | last post by:
Hi there, I am about to build a small db in Access. Among the tables I plan to have are a Person table, an Event table, and an EventRegistration table. The EventRegistration table will...
6
by: Champika Nirosh | last post by:
Hi, I have two machine where I needed to have a extended TCP/IP protocol to make the link between the two machines Mean,I need to write a application that compress every data the machine send...
6
by: Adriano | last post by:
Can anyone recommend a simple way to compress/decomress a String in .NET 1.1 ? I have a random string of 70 characters, the output from a DES3 encryption, and I wish to reduce the lengh of it, ...
5
by: zgh1970 | last post by:
Hi, Friends, default DB2 compression library. I am wondering if this option will have any new restriction on RESTORE in the following. (Can I used that backup imsage for restore at the...
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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.