Skip to content Skip to sidebar Skip to footer

Adding Delay On Loading Each Row In Html Table

I am loading data of HTML table dynamically from Jquery. $(document).ready(function () { for (var i = 0; i < StudentsList.length; i++) { LoadRow(StudentsList[i]);

Solution 1:

Working Fiddle

jQuery

$("tbody tr").each(function () {
   $(this).fadeIn($(this).index() * offset);
});  

Link to the result

Hope this is what you are looking for...!!

Solution 2:

Your code is not working because append is getting called at n:1000 for each row. Try following code, it will solve your problem, but it certainly is not a best approach.

$(document).ready(function () {

    for (var i = 0; i < StudentsList.length; i++) {
        LoadRow(StudentsList[i],i);
    }

});
functionLoadRow(student,n) {
        setTimeout(function (student) {
         $("#tbl tbody").append("<tr class='trStyleSummary'><td>" + student.Name + "</td></tr>");
         }, 1000*n);
}

Solution 3:

SetTimeout just runs things once. What you want is SetInterval so it runs like a clock. This is how I would solve it:

// From your example beforefunctionLoadRow(student) {
  $("#tbl tbody").append("<tr class='trStyleSummary'><td>" + student.Name + "</td></tr>");
}    

// Say for example you have these as your students: var students = [{ Name: 'joe' }, { Name: 'matt' }, { Name: 'sherry' }];

// The index of the last studentvar l = students.length;

// Start a Count indexvar i = 0;

// START!var t = setInterval(function(){

  // Load oneLoadRow( students[i] );

  // Increment up
  i++;

  // Check if all is done, if so stop and clear outif (i == l) clearInterval(t);

}, 1000);

Solution 4:

Should try this way

$(document).ready(function () {
    LoadRow(StudentsList);        
});

functionLoadRow(list) {
    if(list != undefined || list.length < 1) {
        // done// do something elsereturn;
    }

    // Get first itemconst student = list.shift();

    $("#tbl tbody").append(`<tr class='trStyleSummary'>td>${student.Name}</td></tr>`);
    setTimeout(function (student) {
        // Recall the function after 0.15 secondLoadRow(list);
     }, 150);
}

Post a Comment for "Adding Delay On Loading Each Row In Html Table"