aramiz
(Yaramiz)
1
Hi. How can i convert my string
to int
and then sort them?
$sort = new CSort();
$sort->attributes = array(
'minprice'=>array(
'asc'=>'minprice asc',
'desc'=>'minprice desc',
),
);
Now the result is: 
+-----------------+
| name | minprice |
+------+----------+
| bmw | 2300 |
| fiat | 22420 |
| mers | 22100 |
| ford | 1960 |
+-----------------+
And i’m trying to get this one:
+-----------------+
| name | minprice |
+------+----------+
| fiat | 22420 |
| mers | 22100 |
| bmw | 2300 |
| ford | 1960 |
+-----------------+
I know that the promlem is in minprice
type = string and i have to compare it as integer.
mikl
(Mike)
2
Try this (if you use MySQL):
'asc' => 'CAST(minprice AS UNSIGNED) ASC',
'desc' => 'CAST(minprice AS UNSIGNED) DESC',
aramiz
(Yaramiz)
3
[color="#FF0000"]Column not found: 1247![/color]
minprice
is not column of table. I select it:
MIN(price) as minprice
mikl
(Mike)
4
Well, maybe it’s really too hard to guess, but did you try this: 
'asc' => 'CAST(MIN(price) AS UNSIGNED) ASC',
'desc' => 'CAST(MIN(price) AS UNSIGNED) DESC',
aramiz
(Yaramiz)
5
Thanks. 
Another problem with CSort:
when i push sort
button it includes all values from table. But i need him only sort selected values.
For example:
Before sort
+-----------------+
| name | minprice |
+------+----------+
| bmw | 2300 |
| fiat | 4200 |
| mers | 5500 |
| ford | 1960 |
+-----------------+
after sort:
+-----------------+
| name | minprice |
+------+----------+
| ford | 1960 |
| bmw | 2300 |
| fiat | 4200 |
| mers | 5500 |
| toyo | 7000 |
| audi | 7061 |
| bumb | 9000 |
+-----------------+
aramiz
(Yaramiz)
6
And how can i sort non table values ( i have added one column and put there calculated values).
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'hotel-grid',
'dataProvider'=>$provider,
'columns'=>array(
.....................
array(
'name'=>'calculated',
'type'=>'html',
'value'=>'"<b>".calculateFunction($data->minprice,$x,$y)." %</b>"',
),
.....................
),
mikl
(Mike)
7
You should put that calculation into the database, too.