$.fn.yiiListView.update not returning the jqXHR object $.fn.yiiListView.update (and for that matter: $.fn.yiiGridVi
Posted 06 March 2012 - 10:49 AM
Posted 11 May 2012 - 07:07 AM
I proposed a patch in that topic. But Mdomba rightfully added that my patch breaks the pattern for the returnvalue of the update function. This is because $.fn.yiiGridView.update function allready returns the jquery object for the gridview.
Since I don't know if the returnvalue for that function is used elsewhere, I guess there is no choice but to devise an other way to reach the jqXHR object. All I can think off at this moment is to make the jqXHR object available from within the yiiListView object like so $.fn.yiiGridView.getRequest() or something like that, but that seems a little dirty. Also, it would break when more than one listview is used on the same page.
Is there anyone that can shine a light on this problem? Or come with a more elegant solution? Or even a semi-elegant workaround?
I would really like to be able to update future versions of Yii without my site breaking!
Posted 12 May 2012 - 06:19 AM
a bit of brainstorming:
the gridview update method is more complex... as it does more things than just calling an ajax method, and it can work even without making the ajax method at all... that's a problem as I see to make it return always a consistent value (jqXHR object)...
I guess that if we would like to return the jqXHR object then a bit of refactor would be needed there... maybe to create two methods from that one... or as you suggested above to find another way of returning that object.
Posted 15 May 2012 - 02:43 AM
If I'm able to abort the first request (if it's still running off course) right before I start the second request, this would solve the problem.
I guess it could be something like: $.fn.yiiGridView.getLastXmlHttpRequest()
Or it could be a property like: $.fn.yiiGridView.lastXmlHttpRequest
You'd have to call this method or property right after the call to the $.fn.yiiGridView.update function to be (not entirely) sure that you get the right jqXHR object. (It still feels a little dirty, though )
If you don't get what I'm goin' on about than I could post some sample code that I envision using this method. Let me know what you think!
Posted 15 May 2012 - 03:41 AM
In CActiveForm we have something similar with the "validateOnType"... there the ajax() call is put in an setTimeout()... and if a new call is made before the old one is issued... the old one is cleared and only the new one is made...
Problem of this approach is that you cannot cancel the ajax request if it is started... it just prevents the queue up of ajax calls....
Posted 15 May 2012 - 07:36 AM
There is one other way I can think of returning an extra variable (similar to "out" variables in C#). But that also seems a little icky. I think it would have to involve passing a function as a parameter to the update function. And I guess the framework wouldn't be served with the bad example that it will set. Since there is no hint of consistency with any other code (at least that I know of).
Posted 16 May 2012 - 05:54 AM
I think this is a very viable option because I can't think of any other reason to have a reference to the jqXHR object than to abort it (but maybe any of you can . Also you could think about making this behavior standard in Yii 2.0 for example (but maybe even in the current branch) 'cause I think it will only break BC in very specific cases.
Posted 16 May 2012 - 06:02 AM
Can you create a pull request for this... or propose the code change?
Posted 16 May 2012 - 10:20 AM
Exactly my point
I'll see what I can do