$(document).ready(function() {
$("#list1").jqGrid({
url: 'example1.php',
/*balabala...*/
gridComplete: function() {
}
});
$("#list2").jqGrid({
url: 'example2.php',
/*balabala...*/
gridComplete: function() {
}
});
/*I want to do something here, but the above grids must be both complete first.*/
Something...
});
How should I do ? Thanks!
The easiest way is to put your “something” in the
gridCompletecallbacks but have the two callbacks check that the other one has finished. Something along these lines:This nicely extends to more than two lists with a couple small modifications:
var how_many_done = 0;instead ofone_done.++how_many_done;instead ofone_done = true;and move it to the top ofdone_checker.if(one_done)withif(how_many_done == number_of_tasks)wherenumber_of_tasksis how many AJAX tasks you have.The general version would look sort of like this:
An even better version would wrap up the state in a closure: