CListView ajax bug

When i use CListView with ajax.

In the view page, after i click the next page at the first time, i got a new content div whose id is same to its parent div id.

Please see the screen shot.


I have had the same problem - the AJAX request appends the tag inside the existing tag rather than replacing it. I did wonder if this was a JQuery issue because I was sending the AJAX replies with the application/xhtml+xml mime type (the site is in xhtml 1.1), and the JQuery documentation does say that the .html function does not work for xml. However, the problem persisted even when I changed the mime type to text/html.

I am running the version 1.1.4.

I have managed to get this working as I think it should, by modifying the jquery.yiilistview.js file - on line 91, I have replaced $(id).html($filtered.size() ? $filtered : $d.find(id)); with $(id).html(($filtered.size() ? $filtered : $d.find(id)).html());.

If I’m not mistaken, the JQuery documentation for the .html function does not say that it can take a JQuery object as an argument, but rather either a string or a function, which is presumably why converting the argument to .html seems to work.

I certainly don’t yet know the framework well enough to be able to say whether this is well and truly a bug, but it does seem to be to me. I don’t like modifying the core itself, so I would very much like someone to tell me whether this is indeed a bug or whether I should be going about it a different way.


Before anything: upgrade to Yii 1.1.5 - you can’t report anything if you’re not using the latest release.

It could have been fixed. You never know. :)

((And, if you want to be certain, grab the nightly build as well. Or checkout the SVN repository)).


Have upgraded to 1.1.5, and the problem is still the same.

Nice catch. I’ve opened a ticket. Some time ago i suggested a change in yiiGridview which is also required for listView. Can you try with this code (replace html() with replaceWith() ):

$.each(settings.ajaxUpdate, function(i,v) {

    var id='#'+v,



    $(id).replaceWith( $filtered.size() ? $filtered : $d.find(id));


BTW: I just realized that there’s a ‘,’ missing after $d=$(data) and i can’t wrap my head around why this doesn’t throw a syntax error. Any idea someone?

in javascript the semicolon is optional as long as there is one statement in a line… and when assigning a value to a variable the "var" is optional too… so the above code is

  var id='#'+v, $d=$(data)


and it could have been written like:




Wow, you learn something new every day. Do you maybe have an “official” reference? Did a quick google search and couldn’t find anything useful.

Still i’d suggest to add a ‘,’ for clarity. And i’d consider the code still wrong, as it’s also missing “var” then (we’re declaring here…). Correct it should then be:

var id='#'+v  

var $d=$(data)  

var $filtered=$d.filter(id)

Using ‘,’ you can use a single var for multiple declarations:

var id='#'+v ,

    $d=$(data) ,


As I wrote above

if you are assigning a value to a variable, it’s the same if you use “var” or not… it’s just matter of taste…

using var is more cleaner… but without var the code is shorter ;)

as for googling… just google "javascript semicolon" there are plenty of references…

Note: I fixed this issue… replaced html() with replaceWith()

Hmm. IMO we should create the most standards compliant code possible. Even though using "var" might be optional (which is also new for me), it will save you from clashes caused by closure.

function x() {

  var a=5;

  function y() {

    a=7;   // is different from var a=7; !!



  alert (a);  // will alert "7". If var a=7 was used, it would alert 5


Thanks for fixing, but please also add the ‘,’ for clarity.

EDIT: fixed example

Ah, you forget js so fast, if you don’t use it for some time :) Now i remember what was going on, if you miss the “var”: you’re assigning a property in the global context. That’s something different than declaring a variable in the current context with var. Read more here:


So still: having the ‘,’ in yiiGridView and yiiListView would be correct. I could commit it, too, but don’t want to interfere too much with the devs… ;)

Just added the ‘,’… I too don’t like to “interfere” with the code of others that’s why I did not add the colon in the first place… but as you pointed out that is not just a coding style… but a possible error… so in this case I don’t see why not commit…

Thanks, feels much better now :D

Hi guys!

Thanks for the replies. Sorry I wasn’t about earlier - catching some sleep :P

I’ve made the replaceWith replacement (and comma addition) as suggested, and it works fine, although I suppose you already know that since you have committed it.

Yes… if you checkout the latest SVN trunk this is fixed there…