Visibility of buttons in CButtonColumn for edge records

Hi,

Suppose, someone want to display particular button in CButtonColumn for all CGridView records except first and last.

Doing it for first is quite easy and requires only:


'visible'=>'$row > 0'

But how to do the same for last record? How to count all records in PHP expression executed for deciding whether button is or is not visible?

Using ActiveRecord or DAO there for counting record in DB doesn’t seems to be a wide idea for performance reasons.

generaly to get data for a CGridView you use CActiveDataProvider… and this in turn has totalItemCount - http://www.yiiframew…temCount-detail

Need to reopen old thread.

That generally doesn’t answer the question, in my opinion. So what, that I can count all data rows passed to CGridView data provider? With what parameter I should compare this number? Citing documentation:

gives us that there is now way to get to data provider in expression evaluated per each row.

So the question remains open. How to display particular button for all rows except last one? What expression should be used for visible parameter?

And speaking about total number of rows. Does CGridView.summaryText takes CActiveDataProvider->criteria->condition into consideration? For me it seems that non. I have 15 records in one of my tables, and one of them has del column > 0. When I passed CActiveDataProvider with criteria set to CDbCriteria>condition = ‘del = 0’; I got summary text saying: “Positions 1-14. Total count: 15.” (or something similar, as I’m translating Polish message into English".

Of course I have only fourteen records in CGridView and no pager, as in fact there are only fourteen, not fifteen total records.

Attribute CGridView.summaryText was not modified by my in anyway. It displays default text. And pagination component of CActiveDataProvider is set to ‘pagination’=>array(‘pageSize’=>20), so there is now way that last records is on some other page. It simply looks like summaryText gives incorrect record count.

Hey Trejder,

Did you finally find an expression for determining the last row of a CGridView?

I am implementing some functionality where the user can sort rows up and down and I am providing UP and DOWN action buttons. Obviously I do not want to display a DOWN button on the last row. Hiding the UP button on the first row is easy (‘visible’ => ‘$row != 0’) as you said.

But I am stuck displaying a DOWN button on the last row (that, when clicked, does nothing)

Thanks…

Stratos

Hi stratosgear,

Nope! I dropped, it leaving as you told – having down button also in last row (and even up button in first! :], that do nothing for this row. Because client, for which I was developing that application told me, that this is not a problem at all for him, and that he even prefer version with all (four) buttons in every row, for visual reasons.

Later, thinking about it, I found only one solution, that you might consider – purely jQuery one. Give your “down” buttons a special class, then select using jQuery all of them (all objects having that class), find the last one in selected range and hide it, using .css(‘display’, ‘none’). Should work…

CSS first-child and last-child selectors would have done the trick I think:




buttons:first-child, buttons:last-child {

  visibility: hidden;

}



Exactly man, exactly! :] Thanks (+1)! :]

If somebody still needs it, here is my solution:


'visible' => '$this->grid->dataProvider->getPagination()->getOffset()+$row+1 != $this->grid->dataProvider->totalItemCount',