views:

42

answers:

2

Cocoa Touch's UITableView allows a user to scroll through large numbers of data rows with good performance because it recycles table rows. Rather than create a GUI element for every single data row, a limited number of table rows is created, and simply updated with the relevant data as the user scrolls, giving the illusion of navigating up and down a very large number of table rows.

Has anyone seen this done in javascript? Is there a plugin available anywhere that will do this for me?

A: 

Actually the algorithm is not difficult at all. If you know javascript you should be able to write this. The algorithm only needs the height of a cell and the height of the table.

I only know these two: Apple's Dashcode javascript Framework has an implementation of a Table. You could take a look and see if that is what you need. Or Cappuccino Framework which is basically Objective-J but behind the scenes is Javascript.

nacho4d
Yes, the basics are simple. I'd like scroll wheel support too, don't know how much work that's going to be. And I'll have to handle animating the cells as they pass in and out of view, which, while not hard, will take me a few hours at least.
morgancodes
A: 

I don't think that this is necessary in JS.

It is done this way in Obj-C in order not to allocate and initiate the views in table rows.

In JS the rows are just text (no allocation needed) that you should hold somewhere anyway - you might hold only the text without the HTML and wrap it with HTML when the row becomes visible, but I don't think it is worth your time.

I don't believe that this approach will make the HTML table faster...

Michael Kessler
Michael, I'll be working with potentially thousands of rows. It's very time-consuming for the browser to create all of those dom object, so I'm looking for ways to optimize and reuse dom objects.
morgancodes
Ok. And the user will be patient enough to scroll thousands of rows? Usually there is a paging or search in web sites in order to reduce displayed data amount and increase site's usability. Well, I suppose you have already done your research and assumptions on all these questions. BTW, are you about to bring the new rows with AJAX?
Michael Kessler
Yes, the new rows would be brought in via ajax. And, absolutely, there's a search as well. Good point about the patience of the user, though I think that point applies to paging through 1000's of results just as well as scrolling.
morgancodes