SHOW:
|
|
- or go back to the newest paste.
| 1 | public function relations() {
| |
| 2 | return array( | |
| 3 | 'ca' => array(self::HAS_MANY, 'ContactAction', 'contact_id'), | |
| 4 | ); | |
| 5 | } | |
| 6 | ||
| 7 | public function search() {
| |
| 8 | $criteria = new CDbCriteria; | |
| 9 | $lastactivity_sql = '(select max(date) from tbl_contact_action where contact_id=t.contact_id)'; | |
| 10 | $criteria->select = array('t.*', $lastactivity_sql . ' as lastactivity');
| |
| 11 | $criteria->addCondition('t.status<>"Deleted"');
| |
| 12 | $criteria->compare($lastactivity_sql, $this->lastactivity); | |
| 13 | $sort = new CSort; | |
| 14 | $sort->defaultOrder = array('name' => CSort::SORT_ASC);
| |
| 15 | $sort->attributes = array( | |
| 16 | 'name' => 'name', | |
| 17 | 'email' => 'email', | |
| 18 | 'status' => 'status', | |
| 19 | 'createdon' => 'createdon', | |
| 20 | 'lastactivity' => 'lastactivity', | |
| 21 | ); | |
| 22 | $sort->applyOrder($criteria); | |
| 23 | ||
| 24 | return new CActiveDataProvider($this, array( | |
| 25 | 'criteria' => $criteria, | |
| 26 | 'sort' => $sort, | |
| 27 | 'pagination' => array( | |
| 28 | 'pageSize' => Yii::app()->user->getState('contactPageSize', Yii::app()->params['RECORDPERPAGE_ADMIN']),
| |
| 29 | 'currentPage' => Yii::app()->user->getState('Contact_page', 0),
| |
| 30 | ), | |
| 31 | )); | |
| 32 | } | |
| 33 | CGRIDVIEW on display page | |
| 34 | --------------------------- | |
| 35 | <?php | |
| 36 | $this->widget('ext.selgridview.SelGridView', array(
| |
| 37 | 'id' => 'contact_grid', | |
| 38 | 'dataProvider' => $dataProvider, | |
| 39 | 'pageSizeVar' => 'contact', | |
| 40 | 'columns' => array( | |
| 41 | array( | |
| 42 | 'id' => 'autoId', | |
| 43 | 'class' => 'gridCheckBoxColumn', | |
| 44 | 'headerHtmlOptions' => array('class' => 'checkbox paracheck'),
| |
| 45 | 'htmlOptions' => array('class' => 'checkbox paracheck'),
| |
| 46 | ), | |
| 47 | array( | |
| 48 | 'header' => 'Last Activity', | |
| 49 | 'class' => 'gridDataColumn', | |
| 50 | 'name' => 'lastactivity', | |
| 51 | 'value' => 'CommonFunctions::formatDateTime($data->lastactivity)', | |
| 52 | 'htmlOptions' => array('class' => 'maincell'),
| |
| 53 | 'headerHtmlOptions' => array('title' => Yii::t('app', 'LBL_LIST_SORT_DATE_TITLE'))
| |
| 54 | ), | |
| 55 | ), | |
| 56 | )); | |
| 57 | ?> | |
| 58 | ||
| 59 | ||
| 60 | Error | |
| 61 | ------ | |
| 62 | CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.lastactivity' in 'order clause'. The SQL statement executed was: SELECT t.*, (select max(date) from tbl_contact_action where contact_id=t.contact_id) as lastactivity FROM `tbl_contact` `t` WHERE t.status<>"Deleted" ORDER BY lastactivity, `t`.`lastactivity` LIMIT 10 |