views:

33

answers:

4

Hi All, I'm doing the server side sorting in datatable plugin .Data takes 4-5 seconds to load, in the mean time if the user clicks on other headers it will again trigger the ajax call. Please help me on how to restrict the user when the servers side data is still in processing state. Is there any initial function where i can check custom Flag status & stop the sortable till processing is done.??

Highly appreciate the quick response.

Thanks, Janardhan

+2  A: 

When you first get the request, disable the button. Then enable the button in a callback function which is triggered when the server finishes. That's how you'd do it, but if you want code, then give code.

EMMERICH
sillyMunky
I told him how it can be achieved. Difficult to provide an implementation when the only environment details we're given is "jquery".
EMMERICH
janardhan
Also, please look at the datatables server side link which i have provided.
janardhan
@EMMERICH he seemed to already know that is how to achieve what he wanted, just didn't know how to actually do it. I offered a solution that will work for pretty much any code he is using but got no up votes :(@janardhan "here the problem is how to disable the table header click temporarily" That's what hiding the element does. When it is hidden it cannot be clicked on and the click event will not fire. Is the problem how to select that element? Or do you want a way that it will still show but not be clickable?
sillyMunky
What I suggested was completely different from setting a flag as he suggested. Don't be bitter because your answer didn't get any up votes.
EMMERICH
"What I suggested was completely different from setting a flag as he suggested" he asked what functions he could use and he asked *how* to do it, neither of which you answered. If you ask a mechanic how to fix your car and get the answer "well, you make it work then you start it up" it's useless. I gave your answer with actual information that can help as well, and get an unexplained downvote. Your answer is no better or more useful than mine, misses vital information and treats the OP like an idiot but gets 2 upvotes. What a waste of my time.
sillyMunky
"Please help me on how to ..." - seems to be quite an open question to me. He asked for help with a certain goal in mind, and I answered with how I'd achieve it. What was written after the question were his initial thoughts on how HE would do it, which I didn't agree with. To go back to your car metaphor, it's like being a mechanic and having someone say "how can I make my car work? I was going to drive it off a cliff" and replying "it would be better if you replaced the battery". Bitter about up/down-votes, you are the essence of Stack Overflow.
EMMERICH
janardhan
"Hiding the table header is not at all a solution.table should be visible."Before you posted this comment I had posted what you need to do to disable and then re-enable the click action of the button, without hiding it. Did you try it? Do you understand what it is doing? If so, what is the problem?
sillyMunky
+1  A: 

Just a quick tip:

  • set async: false
  • disable sorting buttons
  • enable them upon successful request
fabrik
async: false won't help, if the user can't click on the button (disabled) it will make no difference (except possibly slow/hang page responses). If the user can click on the button, the request will still be stacked up for being sent off when current one completes.
sillyMunky
A: 

If memory serves me correctly jquery has 3 functions like ajaxStart(), ajaxError() and ajaxComplete().

Simply disable the whole grid/just the grid header when ajaxStart and enable it again when either ajaxError (where you can do some error handling) or ajaxComplete.

GxG
A: 

Hello, there are a variety of ways to do this, the easiest will depend on your code.

$(document).ajaxSend( function(){
   $('controls_selector').hide();
}).ajaxComplete( function(){
   $('controls_selector').show();
});

Will do it, however this will disable them for the duration of any ajax event on your page. The documentation describes how you can use the callback function's parameters to determine the nature of the ajax call and selectively show/hide those elements.

This way you can avoid digging in and playing with the code for the plugin.

Let me know if you need more info/help, Good luck :)

===================

update: the sticking point seems to be that you don't want to hide the elements, you want a way to temporarily disable the event handlers and since they are buried in datatables you don't want to modify them. I would do the following:

var tableheadclone = $('#mytableid thead>tr>th').clone(true);

then write that clone somewhere else and hide it (or keep it in a global js variable). You can then use

$('#mytableid thead>tr>th').unbind('click');

to remove the event handler.

You can re-instate the event handler using the replaceWith() jquery function.

More information or code would be helpful if you can't work it out from here.

sillyMunky
please refer my above comments. Is there a way we can bind the click to whole parent, so that child clicks are not detected by sorting plugin. i see some limitations in the capture mode (opp to bubbling)
janardhan
My updated answer gives a complete solution to your problem. If you can't work out how to implement it we need more details.
sillyMunky
who voted my answer down and why?! I've clearly given a lot more useful information and help than people who are getting upvotes ... what the hell is going on?!
sillyMunky
I dint Vote it down..
janardhan