0

i have a table that display data whenever a user clicks the start event button,but i need to know how to append the records when the user clicks the start button again,the previous record gets overridden

here is my javascript code

function DisplayData(downTime) {
        console.log(downTime);
        var newContent = '';
        $.each(downTime.data, function (i, item) {
            newContent += Hesto.Html.StartTR(item.downTime);     
            newContent += Hesto.Html.CreateTD(item.CategoryName);
            newContent += Hesto.Html.CreateTD(item.StartTime);
            newContent += Hesto.Html.CreateTD(item.EndTime);
            newContent += Hesto.Html.CreateTD(item.Comments);
            newContent  = Hesto.Html.EndTR(newContent);
        });
        $('#DowntimeList').html(newContent);
 }

and here is my html code:

<table id="Downtimetable" class="hesto">
            <thead>
                 <tr>
                     <th>End Of DownTime</th>                   
                     <th>Category Name</th>
                     <th>Start Time</th>
                     <th>End Time</th>
                     <th>Comments</th>
                 </tr>
             </thead>
             <tbody id="DowntimeList">

             </tbody>
             <tfoot>
             </tfoot>
        </table>
1
  • I would suggest using a data binding library such as knockout as well. because this would then product nice looking HTML and javascript code. Commented Apr 16, 2014 at 8:44

3 Answers 3

2

Use append() instead of overwriting the html():

$('#DowntimeList').append(newContent);
Sign up to request clarification or add additional context in comments.

Comments

1

As you suggested in the title of your question, append() it.

$('#DowntimeList').html(newContent);

Should be

$('#DowntimeList').append(newContent);

Comments

0

Simply use,

 document.getElementById('DowntimeList').InnerHtml = document.getElementById('DowntimeList').InnerHtml+newContent

1 Comment

This is equivalent to what OP currently has, and will overwrite the content for each new row he adds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.