khushal
(Khushal Fadiya)
September 11, 2013, 8:17am
1
Hello Everyone!!!
I have created Data provider from an user defined array.
Now I want to apply sorting based on first field. So Code for it is like :
$dataProvider->sort->defaultOrder=‘field_1 DESC’;
But, If I want to add another field for sorting like if field_1 has same value at that time it will sort based on the field_2 value.
konapaz
(Konapaz)
September 11, 2013, 8:39am
2
Could you give us more details about it please ?
khushal
(Khushal Fadiya)
September 11, 2013, 8:48am
3
$dataProvider=new CArrayDataProvider($array_name, array(
'id' => 'display-grid',
'keyField' => 'user_id',
'sort'=>array(
'attributes'=>array(
'field_1','field_2', 'field_3','field_4','field_5'
),
),
'pagination'=>array(
'pageSize'=>10,
),
));
$dataProvider->sort->defaultOrder=‘field_1 DESC’;
This is my code.
Currently sorting is done based on the "field_1" value. But I want that if 3 rows of "field_1" column has same value at that time sorting is applied on the secondary field as "field_2".
Some Example like Student data is sorted on the student’s first name but if two students have same name then it should check for the last name for those two students and sorting applied.
konapaz
(Konapaz)
September 11, 2013, 10:01am
4
$dataProvider=new CArrayDataProvider($array_name, array(
'id' => 'display-grid',
'keyField' => 'user_id',
'sort'=>array(
'attributes'=>array(
'field_1','field_2', 'field_3','field_4','field_5'
),
),
'pagination'=>array(
'pageSize'=>10,
),
));
$dataProvider->sort->defaultOrder=‘field_1 DESC’;
This is my code.
Currently sorting is done based on the "field_1" value. But I want that if 3 rows of "field_1" column has same value at that time sorting is applied on the secondary field as "field_2".
Some Example like Student data is sorted on the student’s first name but if two students have same name then it should check for the last name for those two students and sorting applied.
check something like this
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort'=>array(
'defaultOrder'=>'field_1 DESC',
'multiSort'=>true, //maybe your solution!
'attributes'=>array(
'field_1','field_2', 'field_3','field_4','field_5'
),
),
));
khushal
(Khushal Fadiya)
September 11, 2013, 11:00am
5
Its working nice but when only CGridview getting refreshed at that time this Sorting is not applied.
konapaz
(Konapaz)
September 11, 2013, 11:38am
6
what did you mean ? works only the first time ?
please give the steps from start to the last step that not working
khushal
(Khushal Fadiya)
September 11, 2013, 11:50am
7
Thanks for giving your Interest!!!
I have created an array and pass that array to the Data Provider as described in previous post.
Now that Data Provider directly pass to the CGridview.
At last I have written down few AJAX code that will refresh only CGridview at every 5seconds.
So when page is loaded first time it is sorting nice but after 5-10 seconds it is not displaying data in the proper manner.
konapaz
(Konapaz)
September 11, 2013, 1:37pm
8
Thanks for giving your Interest!!!
I have created an array and pass that array to the Data Provider as described in previous post.
Now that Data Provider directly pass to the CGridview.
At last I have written down few AJAX code that will refresh only CGridview at every 5seconds.
So when page is loaded first time it is sorting nice but after 5-10 seconds it is not displaying data in the proper manner.
welcome
Are you sure that you send the aprropriate ajax-request with all CGridview parameters ?
check with firebug (network) what parameters sent (without your ajax code). Compares with your ajax one.