Hi All,
I have created a gridview but the sorting is not working.
When I click on the header to sort the "Documents_sort" url is been changed.
When I role over it I can see it is correct.
eg:
link: is /patients/seeAllDocuments/11?type=d&Documents_sort=private
resulting Url: /patients/seeAllDocuments/11?type=d&Documents_sort=document
52 $this->widget('zii.widgets.grid.CGridView', array(
53 'id'=>'patients-grid',
54 'dataProvider'=>$model->search($id, $type, 'p', 'true'),
55 'filter'=>$model,
56 'cssFile'=>'/css/gridview.css',
57 'enablePagination'=>false,
58 'enableSorting'=>true,
59 'beforeAjaxUpdate'=>'js:'. $itemClick,
60 'afterAjaxUpdate'=>'js:'. $itemClick,
61 'columns'=>array(
62 array( 'header' => 'Documents', 'name'=>'document', 'value'=>'CHtml::link($data->document, Yii::app()->createUrl("/documents/documentDownload", array("id"=>$data->id)))', 'type'=>'raw'),
63 array(
64 'header'=>'Type',
65 'name'=>'extension',
66 'value'=>'$data->extension',
67 'type'=>'raw',
68 'filter'=>array('txt'=>'txt', 'pdf'=>'pdf','doc'=>'doc','docx'=>'docx','xls'=>'xls','png'=>'png','jpg'=>'jpg','jpeg'=>'jpeg','csv'=>'csv','bmp'=>'bmp','gif'=>'gif','tif'=>'tif'),
69 'htmlOptions'=>array('class'=>'pd-d'),
70 'sortable'=>true,
71
72 ),
73 array(
74 'header'=>'Private',
75 'name'=>'private',
76 'value'=>'$data->private == "false" ?CHtml::tag("div", array("class"=>"ca-s-t")):CHtml::tag("div", array("class"=>"ca-s-f"))',
77 'type'=>'raw',
78 'filter'=>array('false'=>'Public', 'true'=>'Private'),
79 'htmlOptions'=>array('class'=>'pd-d'),
80 'sortable'=>true,
81
82 ),
83 array(
84 'header'=>'Added by',
85 'name'=>'added_by',
86 'value'=>'$data->addedBy->first_last_id_concat',
87 'type'=>'raw',
88 'htmlOptions'=>array('class'=>'sa-doc-ab'),
89 'sortable'=>true,
90
91 ),
92 ),
93 )); ?>
controller
112 public function search($id, $type, $section = 'p', $activeState)
113 {
114 $search = '1';
115 $counter = -1;
116 $category = array('sa'=>'Safety Assesment', 'd'=>'Document', 'r'=>'Resource', 'ae'=>'Adverse Event') ;
117 if ($section == 'p') {
118 $pksStr = 't.category=:category AND patient_document_lookup.patient_id = :patient_id AND patient_document_lookup.active_state = :active_state';
119 $criteria=new CDbCriteria(array(
120 'join' => 'LEFT JOIN patient_document_lookup on (patient_document_lookup.document_id = t.id)',
121 'params' => array(':category'=>$category[$type], ':patient_id'=>$id, ':active_state'=> $activeState),
122
123 ));
124 } else if ($section == 'fn') {
125 $pksStr = 't.category=:category AND field_nurse_document_lookup.field_nurse_id = :field_nurse_id';
126 $criteria=new CDbCriteria(array(
127 'join' => 'LEFT JOIN field_nurse_document_lookup on ( field_nurse_document_lookup.document_id = t.id)',
128 'params' => array(':category'=>$category[$type], ':field_nurse_id'=>$id),
129
130 ));
131 } else {
132 $criteria=new CDbCriteria;
133 }
134
135 if ($this->added_by != '') {
136 list($pksStr, $criteria, $counter) = $this->enctyptedUserSearch($this->added_by, 'last_name', $criteria, $pksStr);
137 }
138
139 if ($counter == 0) {
140 $pksStr .= ' AND t.id = 0';
141 }
142
143 $criteria->condition = $pksStr;
144 $criteria->compare('document',$this->document,true);
145 $criteria->compare('extension',$this->extension,true);
146 $criteria->compare('private',$this->private,true);
147 $criteria->with = array('addedBy');
148
149 return new CActiveDataProvider($this, array(
150 'criteria'=>$criteria,
151 'pagination'=>false,
152 'sort'=>array(
153 'attributes'=>array(
154 'extension'=>array(
155 'asc'=>'extension',
156 'desc'=>'extension DESC',
157 ),
158 'private'=>array(
159 'asc'=>'private',
160 'desc'=>'private DESC',
161 ),
162 'added_by'=>array(
163 'asc'=>'addedBy.last_name',
164 'desc'=>'addedBy.last_name DESC',
165 ),
166 '*',
167 )
168 )
169 ));
170 }
Thanks