View Full Version : Javascript Tips with HTML tables

20 Jun 2010, 09:37 PM

I have two things that I can't really find any good solution to (I have no problem finding solutions that work but none that seems like good code).

Problem number 1:

When using PHP to get data from database. How should i add actions to the rows (or some cell's) click events to differentiate between rows so every row gets some parameters unique to that row passed to a function when events occur. I can simply use DOMElement.onclick = "function(parameters)"; and generate all rows with DOM but how do you think I should store indeces to the rows? Should I use the id attribute and then add event listeners that process the rows ids? The id attribute is fine until I need to store more indeces than available cells+1 (for the row) is occupied plus I don't think the code looks that good using the id attribute. What are your thoughts?

Problem number 2:

When adding a LOT of data from a form to a table using javascript how should I store the data that's added but not visible in the table. Should I add all data to an array and then use that to render the table? This is one of the cleanest solutions I can find to this problem but it breaks some good scripts like table sorters and other table managers when the data is updated. How would you solve this problem?

Thank you for your help.