dantart
(adan)
June 10, 2012, 6:16pm
1
Hi:
I’m using Cgridview, and I can use filters with dropdowns taking values from a recordset or wherever.
But … is there a way to create a filter in which user can select (for example) ">6", referring to filter rows with that column values greater than 6 ?
In same way , less than, greater or equal than … …
Thank you
softark
(Softark)
June 11, 2012, 1:33am
2
As you know, you can give an array of ‘value’=>‘text’ pairs as the filter. And in ‘value’, you may include the comparison operators.
$filter_array = array(
'1' => 'One',
'2' => 'Two',
'<10' => 'Less than ten',
'>=10' => 'Ten or more',
);
...
array(
'name' => 'some_count',
'filter' => $filter_array,
)
dantart
(adan)
June 11, 2012, 6:03am
3
softark … yes, I knew it … but I want any value … i mean, I want the user to put anything he wants … <5 , <10, <64, <154 … anything … not fixed values
softark
(Softark)
June 11, 2012, 6:20am
4
I see.
So you want a dropdownlist filter that can accept on-the-fly entries by the user?
Um, I don’t know what to do with it.
dantart
(adan)
June 11, 2012, 6:31am
5
Well … a dropdown would have just fixed values , what I want is a input text box, and parse what user enters with a function to give my results to the grid
softark
(Softark)
June 11, 2012, 6:55am
6
I’m not sure if I get you right …
The default inline textbox filter should work just as you want out of the box, if your search() method in the model can handle it right.
// in view
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'some-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'name' => 'some_count',
// 'filter' => $some_filter,
),
...
// in search() method in model
...
$criteria->compare('some_count',$this->some_count);
...