Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cgridview: rowCssClassExpression and cssClassExpression have a small bug #1163

Closed
smertnik77 opened this Issue · 11 comments

5 participants

@smertnik77

example:
cssClassExpression=>'true?"":"x"'
or
cssClassExpression=>'true?false:"x"'
makes the html code
<td class>

I mean, even a blank value will be added to the class

@cebe cebe was assigned
@smertnik77

cssClassExpression is from CgridColumn of course)

@cebe cebe referenced this issue from a commit in cebe/yii
@cebe cebe fixed empty css class attribute for CGridColumn
fixes #1163
634d160
@cebe
Owner

problem also existed in CGridView now also fixed in CGridColumn.

@rawtaz

I'm not sure this is a problem/bug in the first place.

@smertnik77, where are you looking when you conclude that the result is <td class></td>? I am guessing you looked in Chrome's developer tools or something like that, and not in the actual HTML source code that is sent to the browser.

Looking at the diffs from @cebe's commits, my impression is that what was previously output isn't <td class></td> but rather <td class=""></td>, and IMO that is valid HTML. It's just a class attribute that doesn't have any classes in it.

I also tested this now and I do get the class="" for the following code:

<?php

$dataProvider=new CArrayDataProvider(array(
    array('id'=>'Foo1', 'bar'=>'Bar1'),
    array('id'=>'Foo2', 'bar'=>'Bar2'),
));

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'id',
        array(
            'name'=>'bar',
            'cssClassExpression'=>'true?false:"x"',
        ),
)));

Yii::app()->clientScript->registerCss('foo', '
.yada
{
    background-color: red;
}
');

If on the other hand people prefer not to have the class output when it's empty, I think that's fine. But it's hardly a bug.

@mdomba
Collaborator

I agree with @rawtaz the output is all standard as the quotes are there, so this "fix" is not really needed but if it's requested we can add it.

@cebe
Owner

So do we want to "fix" it? @mdomba @samdark @qiangxue ?

One other case that can occur is <tr class="myclass "> with a whitespace inside attribute value, but I think it is still valid html then.

@cebe
Owner

@smertnik77 was your bug report about the missing ="" or about an empty class attribute?

@mdomba
Collaborator

IMO it would be more elegant to have clean HTML code so I'm for adding this simple fix.

@cebe
Owner

Thats also how I see it, vote for it. @rawtaz changed label from Bug -> Enhancement ;-)

@creocoder

Agree with @mdomba about having clean HTML code, so good micro-enhancement.

@rawtaz

Good @cebe. We should do this with many more issues marked as bugs, i.e. make them features ;)

@smertnik77

@cebe - about an empty class attribute, I know english bad, sorry

@cebe cebe closed this issue from a commit
@cebe cebe CGridview does not create empty class attribute
fixes #1163 where rowCssClassExpression or rowCssClass could be empty
for certain rows.
7428985
@cebe cebe closed this in 7428985
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.