Scroll to appropriate row on table after refresh

This might be a bit difficult to explain but I'll try to be as clear as possible.

I have a page that lists appointments that need to be confirmed.  A user will open this page and click on the first appointment in the list.  This will take them to another page where the details of the appointment are located.  On this second page the user will update fields and submit the form, marking it as confirmed.  If the user could not contact the person who the appointment is with, then they will click a button to designate the reason, no-answer, phone disconnected, etc...  In either case the db table is updated and the user is redirected back to the list of appointments.  This is where my question comes in.

If the user confirmed the appointment, when the list page reloads, that appointment will no longer be listed, so if we confirmed every appointment, they would always be working on the first record and all would be well.  Since they don't confirm every appointment, they start working their way down the list.  The list usually contains approximately 800 appointments.  What I would like to do is when the user is redirected back to the list page that they will have the next record already highlighted for them and have it scroll into view.  Where I have a problem is determining which row of the table they need to be directed to as well as how this will translate into a scroll position.

To make this a bit more difficult, the table can be sorted by any of the columns, which is done by storing the sort field and ascending or descending in hidden form fields in a form that posts back to the same page and submiting that form.  If the user does re-sort the table, then they will go to the top record of the table.  I have no problem with this, but when they come back to the list from confirming (or failing to confirm) an appointment, then I would want the sort order to be the same as when they went to the appointment detail page.

At this point I don't have any code to handle all of this, it simply redirects back to the list page after the user confirms an appointment and they lose their sort order and position.  

My current thoughts on the matter are to add hidden form fields for the sort order and direction and the row number into the detail page, so when the detail page is submitted it will have that information which can then be submitted via form values back to the original list page.  This should give me most of what I want.  I'll be able to get the sort order and direction right, but I'm still not sure how to scroll down to the appropriate row in the table.  

Any thoughts on getting the scroll position, or other ideas on how to handle this situation would be appreciated.

Thanks,

Neal.
LVL 19
nschaferAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cem TürkSenior Software EngineerCommented:
you can;

give rows unique names
when user clicks a button to designate the reason store the row name in a cookie
when page is loaded you can get the name from the cookie and scroll to it
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nschaferAuthor Commented:
I hadn't thought about cookies, good thought.  How do I scroll to the selected row though?  I know how to scroll to a position, but I don't know how to get the vertical position of a row.  Would offsetTop for the row give me the correct value?
0
Cem TürkSenior Software EngineerCommented:
i am not good at offsets :\ but maybe you can use internal anchors
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

nschaferAuthor Commented:
cem_turk,

Yes, I see how that could work.  I'll give this a shot and let you know how it goes.

Neal.
0
Cem TürkSenior Software EngineerCommented:
you can do a simple check to determine if row exists before scrolling too,

document.getElementsByName("rowname").length returns 0 if there is no element with that name ;) i will inform you if i find something useful to you.

Cem
0
nschaferAuthor Commented:
Cem,

Thanks for the great ideas.  Here's how I finally did this.

When the user click on a row, the following function is called.
  function selectRow(obj) {
    setCookie('confirmRow',obj.sectionRowIndex);
    document.form1.Encounter.value = obj.id;
    document.form1.submit();
  }
  This gets the row number from the table rather than naming my rows, and saves it in a cookie.

When the page is loaded I run the following function
  function goToRow() {
      v = parseInt(getCookie('confirmRow'));
      if (v > 0 && v < document.getElementById('table1').rows.length) {
        vRow = document.getElementById('table1').rows[v];
        vTop = vRow.offsetTop
        vRow.style.backgroundColor = "#cfcfcf";
        document.getElementById('content').scrollTop = vTop;
      }
  }

I decided to go with the offsetTop rather than with a anchors because I couldn't figure out how to get to an anchor without reloading the page.  I could have specified the anchor in the page that is redirecting back to my list page, but I was trying to keep all of the code relating to this in the original page.

Again, thanks.  I think using cookies is much more efficient in this example than my original idea would have been.

Neal.
0
Cem TürkSenior Software EngineerCommented:
hello Neal,

rowindex is a good idea but if multiple users work on that page the index can point you to another row because if someone else comfirms an appointment when you are working it will not be listed and whole rowindexes may vary. for one user your solution is perfect ;)

Cem
0
nschaferAuthor Commented:
This will be a multi-user app, and I did think about that very issue, because it means someone could be skipped.  Naming the rows, I could run into the same problem though, since the names would have to be either the Encounter Number (which would go away if the appointment was confirmed) or just a counter which would end up being the same as the row number.  Since the table is not sorted by the Encounter Number I can't just use that and move to the next one.

Do you have any thoughts on this?
0
Cem TürkSenior Software EngineerCommented:
i think you can use some info related with the appointment in the name so that it would be unique for example you can include appointment time and persons name in the name of the row. so it will always stay the same.

there is a one more issue my next row can be confirmed by another user, we should take into account too.

i think we can using ids from the database will be the best, if we cant find the row with the related id we can switch to the next id (if there is one :)
0
nschaferAuthor Commented:
>>there is a one more issue my next row can be confirmed by another user, we should take into account too.

Excellent point.  I hadn't thought of that.  I'm thinking I need to update the record when someone goes into it to prevent multiple users from trying to work on it at once.  Unfortunately I can't modify the table structure, but I suppose I could create a table that would be updated with the Encounter Number when someone opens that appointment and then have the detail page check to ensure that the Encounter Number does not exist before allowing the user to work on it.  I can imagine there might still be problems if people clicked simultaneously.

I think in the current processes the users are each working on seperate locations, or ranges of the alphabet.  Perhaps I have to give them some filtering options to help prevent overlap.  I'll have to discuss it with the end users and see.  I guess it's time to put on my Systems Analyst hat and talk to the users. ;)

Neal.
0
Cem TürkSenior Software EngineerCommented:
users are always the best to get advice about a project :D i am developing an app in VB and users know the app far more better then me lol

Cem
0
Cem TürkSenior Software EngineerCommented:
Neal, why dont you send the user to next rows confirmation page after confirmation? i think you can place a skip button in the confirmation page too. so that they can abuse the whole list only when they really need to see it :)
0
nschaferAuthor Commented:
Cem,

I've been thinking about having them go right to the next record without going back to the list.  I'd still have similar problems ensuring the record wasn't in use by someone else, but I think I can handle that.  

The Skip button would so they could just go on to the next without confirming the one that pops-up for them?

I'm thinking I'm going to have to create a table for confirmations seperate from the actual appointment table.  This would list the Encounter Number (Appointment Unique ID), The user, Date/Time of attemt and results.  This way when we pull up the list I could highlight those that we have not yet tried to call.  

Having this table would allow me to work either from the list or just moving to the next record that has not been confirmed.

Hope you don't mind being used as a sounding board.  

Neal.
0
Cem TürkSenior Software EngineerCommented:
>The Skip button would so they could just go on to the next without confirming the one that pops-up for them?
yes, user could want to confirm it later

i am just trying to help you a bit and get different ideas from you ;)
everyone needs each others experience.

i hope to hear from you.

Cem

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.