From: Dr J R Stockton on
In comp.lang.javascript message <2b8192d5-88aa-45df-b72b-4b698a869c00(a)j1
4g2000yqm.googlegroups.com>, Sat, 26 Dec 2009 11:58:43, Stefan Mueller
<seekware(a)yahoo.com> posted:
>I've a html table which is sortable by clicking on the header of each
>column.
>Because the sorting sometimes takes a couple of seconds I'd like to
>prevent that the user can click the header of a column while the sort
>function is running.
>
>Here's my approach:
>I do at the end of the sort function
> sort_end_time = new Date().getTime();
>and at the beginning of the sort function I check how much time has
>passed after the sort function finished last time
> if ((new Date().getTime() - sort_end_time) > 300) {


Rather than use Date, would it not be better to do something like

Busy = true
CallLengthySortFunction()
Busy = false

and test Busy at the start of your onClick routines?

That does not address the re-draw time question.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
From: Stefan Mueller on
On Dec 27 2009, 10:33 pm, Dr J R Stockton
<reply0...(a)merlyn.demon.co.uk> wrote:
> Rather than use Date, would it not be better to do something like
>
>         Busy = true
>         CallLengthySortFunction()
>         Busy = false
>
> and test Busy at the start of your onClick routines?
>
> That does not address the re-draw time question.

Yes, it would be much better to do something like
Busy = true
CallLengthySortFunction()
Busy = false
But it does not work.

The 'CallLengthySortFunction()' locks the whole javascript engine so
that the onClick event is not executed before the
'CallLengthySortFunction()' has finished. If you click on a column the
onClick event is "cached" and first when the 'CallLengthySortFunction
()' has finished the onClick event gets executed and then 'Busy' is
set False and not True anymore.

That's the reason why I'm trying to do something with the time
function.

However, like you mentioned, even if your solution with 'Busy' would
work I still had the problem that 'Busy = false' (last javascript
command) is executed BEFORE the browser has redrawn (refreshed) the
table on the screen. That means that 'Busy' is False before the user
sees the new sorted table on the screen and that he already can click
on another column before the newly sorted table is displayed.

I need any possibility, any event where I can execute the command
'Busy = false' or in my case to save the time just after the browser
is ready again (after the refresh which sometimes takes several
seconds).

Stefan
From: David Mark on
On Jan 7, 4:41 am, Stefan Mueller <seekw...(a)yahoo.com> wrote:
> On Dec 27 2009, 10:33 pm, Dr J R Stockton
>
> <reply0...(a)merlyn.demon.co.uk> wrote:
> > Rather than use Date, would it not be better to do something like
>
> >         Busy = true
> >         CallLengthySortFunction()
> >         Busy = false
>
> > and test Busy at the start of your onClick routines?
>
> > That does not address the re-draw time question.

There is no such question. ;)

>
> Yes, it would be much better to do something like
>   Busy = true
>   CallLengthySortFunction()
>   Busy = false

That's exactly the same. (?)

> But it does not work.
>
> The 'CallLengthySortFunction()' locks the whole javascript engine so
> that the onClick event is not executed before the
> 'CallLengthySortFunction()' has finished. If you click on a column the
> onClick event is "cached" and first when the 'CallLengthySortFunction
> ()' has finished the onClick event gets executed and then 'Busy' is
> set False and not True anymore.

You are confused. "Cached" user actions are not going to do anything
until you are finished with the above execution. And there's a good
chance that the rendering will be updated on exiting the sort function
(though that is irrelevant). Post a test page that demonstrates your
problem as your descriptions so far can't be accurate.

And forget anything to do with timing. Such strategies are doomed to
fail (if not for you, then for some percentage of your users). ;)
From: Stefan Mueller on
On Jan 7, 11:07 am, David Mark <dmark.cins...(a)gmail.com> wrote:
> You are confused.  "Cached" user actions are not going to do anything
> until you are finished with the above execution.  And there's a good
> chance that the rendering will be updated on exiting the sort function
> (though that is irrelevant).  Post a testpagethat demonstrates your
> problem as your descriptions so far can't be accurate.

Here is a testpage:
http://test.seekware.ch/example.html

Please click once on 'Column 1' and after a few seconds the table is
sorted (just click 'Ok' to close the message box).
Click on 'Column 1' again and watch the message box. 'Busy' is false
and 'Difference' shows the time elapsed after the last sorting.
Now click 'Ok' and just again on 'Column 1' (before the sorting has
finished). Your click will be cached and just after the sorting has
finished the message box appears again. 'Busy' is false again and also
'Difference' shows the time elapsed (a couple of milliseconds) after
the last sorting again (this is the time the browser needs to refresh
the table).

> And forget anything to do with timing.  Such strategies are doomed to
> fail (if not for you, then for some percentage of your users).  ;)

I totally agree! I just thought that this could be the only
possibility. But if there's no possibility, no event where I can save
the time just after the browser is ready again it makes no sense.

To sum up: I'm looking for a solution to prevent clicking on a column
header while the table is sorting.
The only solution I figured out is to add the command 'alert("Sorting
done.");' at the end of the sort function because then the cached
mouse clicks get deleted. But I don't want to display such a message
box. Is there perhaps another way to delete these mouse clicks?

Stefan
From: JR on
On 12 jan, 02:04, Stefan Mueller <seekw...(a)yahoo.com> wrote:
> On Jan 7, 11:07 am, David Mark <dmark.cins...(a)gmail.com> wrote:
>
> > You are confused.  "Cached" user actions are not going to do anything
> > until you are finished with the above execution.  And there's a good
> > chance that the rendering will be updated on exiting the sort function
> > (though that is irrelevant).  Post a testpagethat demonstrates your
> > problem as your descriptions so far can't be accurate.
>
> Here is a testpage:
>  http://test.seekware.ch/example.html
>
> Please click once on 'Column 1' and after a few seconds the table is
> sorted (just click 'Ok' to close the message box).
> Click on 'Column 1' again and watch the message box. 'Busy' is false
> and 'Difference' shows the time elapsed after the last sorting.
> Now click 'Ok' and just again on 'Column 1' (before the sorting has
> finished). Your click will be cached and just after the sorting has
> finished the message box appears again. 'Busy' is false again and also
> 'Difference' shows the time elapsed (a couple of milliseconds) after
> the last sorting again (this is the time the browser needs to refresh
> the table).
>
> > And forget anything to do with timing.  Such strategies are doomed to
> > fail (if not for you, then for some percentage of your users).  ;)
>
> I totally agree! I just thought that this could be the only
> possibility. But if there's no possibility, no event where I can save
> the time just after the browser is ready again it makes no sense.
>
> To sum up: I'm looking for a solution to prevent clicking on a column
> header while the table is sorting.
> The only solution I figured out is to add the command 'alert("Sorting
> done.");' at the end of the sort function because then the cached
> mouse clicks get deleted. But I don't want to display such a message
> box. Is there perhaps another way to delete these mouse clicks?

The solution is using a flag ('busy') as a property of the sort
method:

function sort() {
if (arguments.callee.busy) { return; }
arguments.callee.busy = true;
// do the sort stuff.
arguments.callee.busy = false;
}

--
JR