Advanced CGridView

I develop an application for managing events and employees (Vencidi) which we are migrating to Yii.

We have discovered lots of performance improvements, but have found CGridView a bit lacking to what we currently use for data presentation.

We would like to be able to contribute our changes back to Yii and as a result need some help understanding all the provided classes and code practices used by Yii.

We offer our users the ability to show/hide and reorder columns since some of our users find certain data more or less important (eg Accounting is interested in total pay/costs for events, staffing is interested in what events still to be staffed, reporting is interesting in event type diversity).

This feature was originally from: http://www.danvk.org/wp/dragtable/

We did not implement dragable columns, but instead a 3 column view of the available columns with checkboxes to show/hide and the labels are sortable (http://jqueryui.com/demos/sortable/).

We then use multilevel sorting of columns since you usually want something like sort by Last Name and the First Name or sort our event by location followed by date.

We use multilevel sorting which implements things like searching for events occurring in a date range or occurring in the past 5 days to the future (so you can view all the recent and future events in a rolling form). The searches are date type specific so you can search strings with begins, ends, contains, etc, dates with before, after, etc, foreign keys with drop downs, bools with yes/no, etc.

Finally, we save all of the users settings for each table for each user so that they only have to customize their view for the tables one time. (We serialize the settings in a multilevel array in the user MySQL table.)

Problems/things I specifically need help with:

  • We have to be able to search and sort by things that were retrieved in a stat query (eg total pay per user)
  • I would like to be able to autodetect column data type as much as possible (I think CDbColumn will help with this, but I’m not sure how to get that when passed a model.)
  • Not mentioned above, we also process problem cells and apply a special class to them (eg an event that is canceled has a red background, events lacking staffing are yellow)
  • Also, not mentioned above we use shorter labels for our tables views than in an editing for to save space, so I implemented an attributeShortLabel function that could be checked first for header labels. Would it be possible to implement that in the real code. (We overrode, headercellcontent in CDataColumn to be:

protected function renderHeaderCellContent()

	{

       		// Use Short Label if it exists

       		if (method_exists($this->grid->dataProvider->model,'attributeShortLabels') && $this->header===null && $this->name!==null) {

                	$labels= $this->grid->dataProvider->model->attributeShortLabels();

                	if(isset($labels[$this->name])) {

                    	$this->header = CHtml::encode($labels[$this->name]);

                	} else {

                    	$this->header = CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));

                	}

            	}


		parent::renderHeaderCellContent();

	}

  • We are not sure how to handle the "quick search" fields currently in CGridView with our advanced search. It is obviously more simple to search there for quick things, but should a search there appear in the advanced search fields and should we find a way to represent all our advanced searches in the quick search fields

Here is a screenshot of our current screen:

1131

Screenshot-2.png

Resources:

This post: http://www.yiiframew…dpost__p__73140 mentions building in relational queries for things, unfortunately I have previously had problems with stat queries getting thrown off if you try to join too many things someone with more MySQL experience may be able to help.

Ex. For Users we stat number of calls worked and total pay which is

SELECT count(UNIQUE call_id) FROM call_response GROUP BY emp_id

SELECT sum(pay) FROM time GROUP BY emp_id

We have had both things doubled by selecting both with a query like

SELECT m.*, count(UNIQUE cr.call_id), sum(t.pay) FROM member as m LEFT JOIN call_response as cr ON (cr.emp_id=m.emp_id) LEFT JOIN time as t ON (t.emp_id=m.emp_id) GROUP BY emp_id

(It seemed that by joining both MySQL pulled all combinations of time and call_response and member)

This mentions saving searches in the session which is similar to our saving in the database since we would just be persisting that data across sessions:

http://www.yiiframew…with-cgridview/

Does Yii build in any persisting of session data or would we be responsible for saving to the database?

I think that takes care of everything. Does this feel like something that could be built into a widget?

What all will have to be done by config?

Can we sort by a stat column without fetching everything first? (Eg. Maybe in paging by 10s fetching the top 10 in a stat column, then fetch any who have the same value as the 10th and then sort those by the next sort criteria?)

I figured I would start with the CGridView files currently in Yii and then build from there. Is their a Yii roadmap for releases? I want to be careful in building this to be able to build in future CGridView improvements. Also, I’ve heard things about Yii 2.0. Is their a schedule for that release?

Hi Loren and thanks for your interest in the Yii Framework.

There is an older Extension called EditableGridView that tries to implement some of your ideas.

I have not tested it recently, though. One could take some Code snippets and ideas from that if you

implement your own Stuff. Maybe i find the time to continue this extensions soon, who knows.

heres the link:

http://www.yiiframework.com/extension/editablegridview

Thanks, I will look into that.

After some delay, the development of this feature is set to start next week so if anyone has any suggestions, I would love to here them.