Busy Indicator with sorttable.js?

E

eskwayrd

Hi group,

I'm trying to add a busy indicator to the sorttable.js code available
at:
http://www.kryogenix.org/code/browser/sorttable/

(Actually, my version is modified for my needs, such as maintaining
zebra stripes post-sort, multi-column sorting, keeping rows with
subordinate rows together. But my problem exists even with the original
code).

I've implemented a function to turn change a 'progress' div:

function busyProgress(m) {
if (document.getElementById("progress")) {
var myEl = document.getElementById("progress");
myEl.innerHTML = (m) ? 'Busy, please wait...' : '';
}
}

This works great with something like an Ajax function, but with
sorttable.js, the 'progress' div's contents never change. Note that I'd
use something like document.body.cursor.style = 'wait' as well, but
Firefox won't change the cursor style unless the mouse is moved.

If I insert an alert() right after the innerHTML line, then I see the
div's contents being changed.

If I insert a simple delay (using new Date().getTime, and looping until
the desired time has passed), the div's contents do not change.

This is a concern since a number of the tables I need to present, and
wish to allow in-browser sorting, have a few hundred rows. The sort
will complete, but I have been unable to provide a visual indicator
that the sort is in progress.

Has anyone else attempted to do this and had success?

Thanks for any assistance you can provide.
 
R

Randy Webb

(e-mail address removed) said the following on 10/4/2005 8:59 PM:
Hi group,

I'm trying to add a busy indicator to the sorttable.js code available
at:
http://www.kryogenix.org/code/browser/sorttable/

(Actually, my version is modified for my needs, such as maintaining
zebra stripes post-sort, multi-column sorting, keeping rows with
subordinate rows together. But my problem exists even with the original
code).

I've implemented a function to turn change a 'progress' div:

function busyProgress(m) {
if (document.getElementById("progress")) {
var myEl = document.getElementById("progress");
myEl.innerHTML = (m) ? 'Busy, please wait...' : '';
}
}

This works great with something like an Ajax function, but with
sorttable.js, the 'progress' div's contents never change. Note that I'd
use something like document.body.cursor.style = 'wait' as well, but
Firefox won't change the cursor style unless the mouse is moved.

If I insert an alert() right after the innerHTML line, then I see the
div's contents being changed.

If I insert a simple delay (using new Date().getTime, and looping until
the desired time has passed), the div's contents do not change.

This is a concern since a number of the tables I need to present, and
wish to allow in-browser sorting, have a few hundred rows. The sort
will complete, but I have been unable to provide a visual indicator
that the sort is in progress.

Has anyone else attempted to do this and had success?

Thanks for any assistance you can provide.

Call busyProgress, and set a timeout to call your sort function. The UA
does not update until the function finishes. As long as its sorting -
the UA wont change displays. The alert you use causes the function to
stop until the alert is dismissed, so the UA updates.
 
R

RobG

Randy said:
(e-mail address removed) said the following on 10/4/2005 8:59 PM:
Hi group,

I'm trying to add a busy indicator to the sorttable.js code available
at:
http://www.kryogenix.org/code/browser/sorttable/
[...]
I've implemented a function to turn change a 'progress' div:

function busyProgress(m) {
if (document.getElementById("progress")) {
var myEl = document.getElementById("progress");
myEl.innerHTML = (m) ? 'Busy, please wait...' : '';
}
}
[...]

If I insert an alert() right after the innerHTML line, then I see the
div's contents being changed.

If I insert a simple delay (using new Date().getTime, and looping until
the desired time has passed), the div's contents do not change.

This is a concern since a number of the tables I need to present, and
wish to allow in-browser sorting, have a few hundred rows. The sort
will complete, but I have been unable to provide a visual indicator
that the sort is in progress.
[...]

Call busyProgress, and set a timeout to call your sort function. The UA
does not update until the function finishes. As long as its sorting -
the UA wont change displays. The alert you use causes the function to
stop until the alert is dismissed, so the UA updates.

That's a good idea (I think) but there are some usability issues.

Events are buffered while the function runs, so if users are impatient
and try clicks & drags in the meantime (e.g. they click on three or four
'sort' do-dads while the first is running), nothing will happen until it
finishes and then the others will run. Users may consider the
unexpected results to be the OP's fault.

The OP may want to put a div over the entire page or employ some other
tactic to prevent user intereaction with the page while the script runs.

Some play stuff below (the pause function should never be used in a real
page, it's just a quick hack to force a pause).



<script type="text/javascript">

function runThing( thing )
{
toggleMsg();
setTimeout(thing + '(1000);', 10);
}

// This thing just pauses for a short time... hogs the processor!
function doPause( ms )
{
var now = new Date();
var t = now.getTime() + +ms;
while ( now.getTime() < t ){
now = new Date();
}
toggleMsg();
}

function toggleMsg()
{
var d = document.getElementById('msg')
d.style.display = ('none' == d.style.display)? '' : 'none';
}

</script>

<div id="msg" style="font-size: 300%; font-weight: bold;
position: absolute; top: 100px; left: 150px; display:
none;">Wait&hellip;</div>

<input type="button" value="Run it" onclick="runThing('doPause');">
 
R

Randy Webb

RobG said the following on 10/4/2005 11:19 PM:
Randy said:
(e-mail address removed) said the following on 10/4/2005 8:59 PM:
Hi group,

I'm trying to add a busy indicator to the sorttable.js code available
at:
http://www.kryogenix.org/code/browser/sorttable/
[...]
I've implemented a function to turn change a 'progress' div:

function busyProgress(m) {
if (document.getElementById("progress")) {
var myEl = document.getElementById("progress");
myEl.innerHTML = (m) ? 'Busy, please wait...' : '';
}
}
[...]
If I insert an alert() right after the innerHTML line, then I see the
div's contents being changed.

If I insert a simple delay (using new Date().getTime, and looping until
the desired time has passed), the div's contents do not change.

This is a concern since a number of the tables I need to present, and
wish to allow in-browser sorting, have a few hundred rows. The sort
will complete, but I have been unable to provide a visual indicator
that the sort is in progress.
[...]


Call busyProgress, and set a timeout to call your sort function. The
UA does not update until the function finishes. As long as its sorting
- the UA wont change displays. The alert you use causes the function
to stop until the alert is dismissed, so the UA updates.

That's a good idea (I think) but there are some usability issues.

Events are buffered while the function runs, so if users are impatient
and try clicks & drags in the meantime (e.g. they click on three or four
'sort' do-dads while the first is running), nothing will happen until it
finishes and then the others will run. Users may consider the
unexpected results to be the OP's fault.

Have the function set a variable when it runs, and checks for that
variable prior to running. When it finishes, reset the variable.

var functionRunning = false

function something(){
if (functionRunning){return false;)}
else{
functionRunning = true;
//function is not already running so it will execute.
}
functionRunning = false;
}

Might be some flawed logic there, its 2am and typing off my head, but
the general idea is there.

Or, and maybe better, is to check the visibility of the div. If its
visible, fire off. If not, don't. And overly the entire page. The
problem with that is you end up with users that say "I clicked and
clicked and nothing happened". Might be better with an : alert('Be
Patient, I am slowly sorting this monster table');

Or, overlay the page with a div with z-index to cover it all with a
"Sorting table...." like a download status bar or something. Some
animated gif or such to let the user know the browser is busy. Doing
this would avoid the variable situation above.
The OP may want to put a div over the entire page or employ some other
tactic to prevent user intereaction with the page while the script runs.

See Above :)
Some play stuff below (the pause function should never be used in a real
page, it's just a quick hack to force a pause).

It's ironic that you would use that tactic. Its irony is that I was
looking through the archives of clj earlier and ran across this thread:

<URL:
http://groups.google.com/group/comp...+stockton+eval+advice&rnum=3#ed6cf6eeca835f6d
Which discusses the ramifications of giving code such as the pause
function and its problems, especially with new people :)

No biggie, just found it ironic was all.
function doPause( ms )
{
var now = new Date();
var t = now.getTime() + +ms;
while ( now.getTime() < t ){
now = new Date();
}
toggleMsg();
}

But, that function would "hog" the CPU (as noted) where a setTimeout
might work better. <shrug> Its 2AM and I need sleep.....
 
E

eskwayrd

Randy said:
Call busyProgress, and set a timeout to call your sort function. The UA
does not update until the function finishes. As long as its sorting -
the UA wont change displays. The alert you use causes the function to
stop until the alert is dismissed, so the UA updates.

Thanks, Randy.

When said in your short, to the point fashion, it all makes sense now.
I'd seen mention of that technique in other threads/blogs, but for
whatever reason, those solutions didn't seem all that applicable to
this situation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top