Hello, on one of my /admin pages I want to display all the rows if the user is a superAdmin, and some if the user is a regular admin. How would I go about doing this? I would assume it has something to do with the dataprovider, which is set to $model->search. How can I edit search to check certain conditions?
public function search()
$criteria->with = array('program','user');
return new CActiveDataProvider(get_class($this), array(
For example, if SOME_VARIABLE = 2, show only rows with STATUS = X. Thanks for the help!
That’s for whole columns, I want to omit certain rows. However, I have figured out a working solution. It’s probably not the best way, but I went into the CGridView.php file and edited the renderTableRow() function. In it, I checked if the current controller was the one in question and then performed my checks using the dataProvider information:
Adding the compare in your search() function will cause the dataProvider to not return the rows that match that criteria, effectively filtering them out of the grid (the whole row, not just a column.).
If you put the criteria check in the visible param of the grid column, then yes,it would only hide the column. But what you’ve done here is take something that could (and should) be handled by the database and bypassed it so that you’re getting all those rows back and skipping them after. Mdomba’s solution is exactly the one you need and should work perfectly as long as you’re putting the check in the right place.
Yeh I’m using $model->search()…I read in another topic that the AJAX filter ignores the original search restrictions…that’s pretty disappointing. I’ll have to hack a solution in there unless someone knows a good way to do it? Thanks.