Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Show list of data in table with set time out

Show list of data in table with set time out

Scheduled Pinned Locked Moved JavaScript
helpjavascripthtmldatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrkeivan
    wrote on last edited by
    #1

    Hey guys, I know the title is simple but I'm new to javascript and would appreciate if you could help me out here's the deal, I ve got some records that i read from database, and I want to add the to top of my table this is run every 20 seconds

    var interval = setInterval(function () {
    loadTableData(selectedOption);
    }, 20000);

    here's what's happening inside loadTableData function

    function loadTableData(dataType) {
    $.get("/JsonResultlink", null, function (result) {
    var itemAdd;
    $.each(result, function (i, item) {
    loadRecordTimeOut = setTimeout(function () {
    if (result[i].VEHICLEPLATE !== undefined) {
    // build the html code
    itemToAdd = generateRow(result[i], dataType);
    // add to table body
    $('.tto-violation-tablebody').prepend(itemToAdd);
    // if rows exceed 50 remove from bottom
    checkRowCount();
    }
    }, 1000 * i);
    });
    clearTimeout(loadRecordTimeOut);
    });
    }

    loadTableData is called in document ready and then every 2 seconds Now I got 3 buttons that when each is clicked i call loadTableData with new dataType and show the result now the problem is that in the middle of data being added to table i click one button I want the table to clear and the new data be displayed but what i get is that data loading becomes faster and i get both data from previous load and this load, Please help me out and I'd like to learn clean coding so if you have any suggestions please let me know, appreciate it.

    P 1 Reply Last reply
    0
    • M mrkeivan

      Hey guys, I know the title is simple but I'm new to javascript and would appreciate if you could help me out here's the deal, I ve got some records that i read from database, and I want to add the to top of my table this is run every 20 seconds

      var interval = setInterval(function () {
      loadTableData(selectedOption);
      }, 20000);

      here's what's happening inside loadTableData function

      function loadTableData(dataType) {
      $.get("/JsonResultlink", null, function (result) {
      var itemAdd;
      $.each(result, function (i, item) {
      loadRecordTimeOut = setTimeout(function () {
      if (result[i].VEHICLEPLATE !== undefined) {
      // build the html code
      itemToAdd = generateRow(result[i], dataType);
      // add to table body
      $('.tto-violation-tablebody').prepend(itemToAdd);
      // if rows exceed 50 remove from bottom
      checkRowCount();
      }
      }, 1000 * i);
      });
      clearTimeout(loadRecordTimeOut);
      });
      }

      loadTableData is called in document ready and then every 2 seconds Now I got 3 buttons that when each is clicked i call loadTableData with new dataType and show the result now the problem is that in the middle of data being added to table i click one button I want the table to clear and the new data be displayed but what i get is that data loading becomes faster and i get both data from previous load and this load, Please help me out and I'd like to learn clean coding so if you have any suggestions please let me know, appreciate it.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      You need to cancel your first periodic update when you change the table content. Read about it here[^] Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups