Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:28:03+00:00 2026-05-22T17:28:03+00:00

I have a table of many rows in a JQuery UI accordion. I dynamically

  • 0

I have a table of many rows in a JQuery UI accordion.

I dynamically append the table this way:

var resJson = JSON.parse(connector.process(JSON.stringify(reqJson)));
    for ( var i in resJson.entryArrayM) {
        // test if entry has already been displayed
        if ($("#resultTr_" + resJson.entryArrayM[i].id) == null)
            continue;
        $("#resultTable > tbody:last").append(listEntry.buildEntryRow(resJson.entryArrayM[i]));
    }

Firstly I check if a row of the same tr id already exists. If not, I would append to the last row of the table.

It works. But the problem is: every time a row is appended, the accordion would scroll to the first row of the table. Since the table is remarkably long, it makes users inconvenient to scroll down again and again to watch newly-added rows. So how to avoid this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:28:04+00:00Added an answer on May 22, 2026 at 5:28 pm

    First of all, just do one append rather than appending every time through the loop:

    var resJson = JSON.parse(connector.process(JSON.stringify(reqJson)));
    var seen    = { };
    var rows    = [ ];
    var trId    = null;
    for(var i in resJson.entryArrayM) {
        // test if entry has already been displayed
        var trId = 'resultTr_' + resJson.entryArrayM[i].id;
        if($('#' + trId).length != 0
        || seen[trId])
            continue;
        rows.push(listEntry.buildEntryRow(resJson.entryArrayM[i]));
        seen[trId] = true;
    }
    $("#resultTable > tbody:last").append(rows.join(''));
    

    Also note that I corrected your existence test, $(x) returns an empty object when x doesn’t match anything, not null. Not only is this a lot more efficient but you’ll only have one scroll position change to deal with.

    Solving your scrolling issue is fairly simple: find out what element is scrolling, store its scrollTop before your append, and reset its scrollTop after the append:

    var $el       = $('#whatever-is-scrolling');
    var scrollTop = $el[0].scrollTop;
    $("#resultTable > tbody:last").append(rows.join('')); // As above.
    $el[0].scrollTop = scrollTop;
    

    There might be a slight visible flicker but hopefully that will be lost in the noise of altering the table.

    You could also try setting the table-layout CSS property of the <table> to fixed. That will keep the table from trying to resize its width or the width of its columns and that might stop the scrolling behavior that you’re seeing. The downside is that you’ll have to handle the column sizing yourself. But, you could try setting table-layout:fixed immediately before your append operation to minimize the hassle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with many rows, is there any way to find out
In each table have many number of rows with amount. Like this i have
I have this kind of table, it has many rows and each row has
I have a jQuery function to dynamically add rows containing input fields, this exists
I have a table with many rows of data, and I want to show
I have an html table with many rows. I'm currently grouping several rows inside
I have a table, has many rows. for example one of from rows(all rows
I have a table, has many rows. for example one of from rows(all rows
I've got a table containing many rows. The rows are guaranteed to have been
I am having a HTML table with many rows. I have seven columns in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.