How to disable the sorting click on table header when server side data is still processing?
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.
How can I 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?
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.
Just a quick tip:
- set
async: false
- disable sorting buttons
- enable them upon successful request
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.
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();
});
This 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.
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.
精彩评论