Jump to content
Sign in to follow this  
sajan

Dynamic row addition to table

Recommended Posts

Hi how should dynamically add rows to a table.The data is from php output through ajax.Suppose I have a table called

<table id="table1"></table>

.How can i add dynamic values to the table.

Share this post


Link to post
Share on other sites

That depends on what the data obtained from the PHP file looks like.There's not one single way.

Share this post


Link to post
Share on other sites

The data is some descriptions and names.I want to add these to table .And next time i call a different set i have to delete the entire row and add new rows.Any suggestion?

Share this post


Link to post
Share on other sites

Here's a function that removes all children, you can call this function on the table to remove all of the rows in it:

function removeChildren(el){  for (var i = el.childNodes.length - 1; i >= 0; i--)	el.removeChild(el.childNodes[i]);}

As far as building a set of rows, look at the DOM reference on the w3schools site. The functions you will need to use are the document.getElementById function to get a reference to the table, and then the document.createElement function to create the table elements (tbody, tr, td, etc), then the element.appendChild function to add the new elements to the table and maybe document.createTextNode when you want to put text in the cells in the table. There's also a good DOM reference here:http://www.howtocreate.co.uk/tutorials/jav...pt/domstructure

Share this post


Link to post
Share on other sites

Thanks, that link is useful.The delete function worked well in firefox,but in explorer if we delete then dynamically create then delete,if these process repeat few times ,IE crashes.

Share this post


Link to post
Share on other sites

There might be a memory leak somewhere. Watch the memory that IE is using when you're doing that. If it keeps going up then there's a leak in your code. Theoretically, if you add a bunch of elements and check the memory, then delete all those elements, then add them back again, IE should be using approximately the same amount of memory.

Share this post


Link to post
Share on other sites

Open task manager using CTRL-SHIFT-ESC. Click the Processes tab. Go to View -> Select Columns. Make sure Memory Usage, Peak Memory Usage, and Virtual Memory Size are all selected. Watch the memory usage column for iexplore.exe when you're testing. It will be best to not have any other pages open while testing, shut down IE then start it back up again and run your test.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...