Hi,
Want all records from a start date given in field_1 from model to end date not a field in model
How to use filters in CGridView to filter between to dates?
Say in model there is a start date so that field_1 in filters is given. The end date is not in the model. How to use a field in Filters that is not in model
is to to end another case 'datebetweentime': in CGridView or how?
Regards
CGridView filter between dates
Moderators: alexandrleonenko, alexmst
Re: CGridView filter between dates
Hello Henrik
Maybe I misunderstood the question, but I'll try to answer it.
You can specify 2 filters for one field, for example:
Maybe I misunderstood the question, but I'll try to answer it.
You can specify 2 filters for one field, for example:
Code: Select all
'filters' => array(
....
'field_1_min' => array('visible'=>true, 'title'=>'', 'type'=>'datetime', 'table'=>CConfig::get('db.prefix').'your_table', 'sourceFilter'=>'field_1', 'operator'=>'>=', 'width'=>'', 'maxLength'=>'10', 'format'=>'yyyy-mm-dd', 'htmlOptions'=>array('placeholder'=>'Field 1 Min', 'title'=>'Field 1 Min')),
'field_1_max' => array('visible'=>true, 'title'=>'', 'type'=>'datetime', 'table'=>CConfig::get('db.prefix').'your_table', 'sourceFilter'=>'field_1', 'operator'=>'<=', 'width'=>'', 'maxLength'=>'10', 'format'=>'yyyy-mm-dd', 'htmlOptions'=>array('placeholder'=>'Field 1 Max', 'title'=>'Field 1 Max')),
....
),
Re: CGridView filter between dates
Hello Sergey,
I have to make a narrow search with dates like in shopping cart where you use narrow-by-list.
all dates from 1. jan to 15. jan..
In your example i got 2 input date fields field_1_min and field_1_max. Which is fine. Let us remove "table" i use CGridView
But
Only field_1_min exist in table/model ReportsEntityItems, so the Filter only take account for the field_1_min.
How to use the field_1_max as a delimiter even it is not a field in the record?
i want
is it possible in helper CGridView
Many Regards
I have to make a narrow search with dates like in shopping cart where you use narrow-by-list.
all dates from 1. jan to 15. jan..
In your example i got 2 input date fields field_1_min and field_1_max. Which is fine. Let us remove "table" i use CGridView
Code: Select all
echo CWidget::create('CGridView', array(
'model'=>'ReportsEntityItems',
But
Only field_1_min exist in table/model ReportsEntityItems, so the Filter only take account for the field_1_min.
How to use the field_1_max as a delimiter even it is not a field in the record?
i want
Code: Select all
find all records between field_1_min and field_1_max from model ReportsEntityItems
is it possible in helper CGridView
Many Regards
Re: CGridView filter between dates
Hello Henrik
The example I provided to you searches for one field field_1 (this is set by the parameter 'sourceFilter' => 'field_1'), fields field_1_min and field_1_max - does not exist.
You can give a link so I understand what kind of list?
Regards
The example I provided to you searches for one field field_1 (this is set by the parameter 'sourceFilter' => 'field_1'), fields field_1_min and field_1_max - does not exist.
I have to make a narrow search with dates like in shopping cart where you use narrow-by-list.
You can give a link so I understand what kind of list?
Regards
Re: CGridView filter between dates
Hello Sergey
For now i have the site on local host...
I thought that the CGridView filter had the opportunity to filter a list where CgridView can filter between for example two dates:
this example filter one date:
Is there a possibility in CGridView to filter between 2 dates
then i can get a list with all workingshours from imployees from within the start date and end date?
Maybe like i created a case statement in CgridView
It is simple a copy of the 'type'=>'datetime' in line 321 CgridView.php . But here could be the code for the date_end field with the 'type'=>'datebetweentime' so when CGridView see that 'type'=>'datebetweentime' is used it combines the 'type'=>'datetime' and 'type'=>'datebetweentime' to a filter search that gives all records between the two filter variables.
Regards henrik
For now i have the site on local host...
I thought that the CGridView filter had the opportunity to filter a list where CgridView can filter between for example two dates:
Code: Select all
date_start and date_end
this example filter one date:
Code: Select all
echo CWidget::create('CGridView', array(
'model'=>'ReportsEntityItems',
'actionPath'=>'ReportsProjects/sendWorkingHoursManage',
'pagination'=>array('enable'=>true, 'pageSize'=>20),
'sorting'=>true,
'defaultOrder'=>array(),
'condition'=>'status = 1',
'passParameters'=>true,
'filters' => array(
'date' => array('title'=> A::t('reports', 'Created At'), 'type'=>'datetime', 'operator'=>'=', 'width'=>'80px', 'maxLength'=>'', 'format'=>''),
),
'fields'=>array(..),
));
Is there a possibility in CGridView to filter between 2 dates
then i can get a list with all workingshours from imployees from within the start date and end date?
Maybe like i created a case statement in CgridView
Code: Select all
'type'=>'datebetweentime',
It is simple a copy of the 'type'=>'datetime' in line 321 CgridView.php . But here could be the code for the date_end field with the 'type'=>'datebetweentime' so when CGridView see that 'type'=>'datebetweentime' is used it combines the 'type'=>'datetime' and 'type'=>'datebetweentime' to a filter search that gives all records between the two filter variables.
Code: Select all
echo CWidget::create('CGridView', array(
'model'=>'ReportsEntityItems',
'actionPath'=>'ReportsProjects/sendWorkingHoursManage',
'pagination'=>array('enable'=>true, 'pageSize'=>20),
'sorting'=>true,
'defaultOrder'=>array(),
'condition'=>'status = 1',
'passParameters'=>true,
'filters' => array(
'date' => array('title'=> A::t('reports', Date start search'), 'type'=>'datetime', 'operator'=>'=', 'width'=>'80px', 'maxLength'=>'', 'format'=>''), //field in the model
'date_end' => array('title'=> A::t('reports', 'Date end search'), 'type'=>'datebetweentime', 'operator'=>'=', 'width'=>'80px', 'maxLength'=>'', 'format'=>''), //not a field in the model its jus a variable
), // because of the type=>datebetweentime the list will be sorted with alle dates between date and date_end
'fields'=>array(..),
));
Regards henrik
Re: CGridView filter between dates
Hi!
Try using this code:
Fields "date_from" and "date_to" in the table do not exist, both these filters search in the "date" field
Try using this code:
Code: Select all
echo CWidget::create('CGridView', array(
'model'=>'ReportsEntityItems',
'actionPath'=>'ReportsProjects/sendWorkingHoursManage',
'pagination'=>array('enable'=>true, 'pageSize'=>20),
'sorting'=>true,
'defaultOrder'=>array(),
'condition'=>'status = 1',
'passParameters'=>true,
'filters' => array(
'date_from' => array('title'=> A::t('reports', Date start search'), 'type'=>'datetime', 'operator'=>'>=', 'sourceFilter' => 'date', 'width'=>'80px', 'maxLength'=>'', 'format'=>''),
'date_to' => array('title'=> A::t('reports', 'Date end search'), 'type'=>'datetime', 'operator'=>'<=', 'sourceFilter' => 'date', 'width'=>'80px', 'maxLength'=>'', 'format'=>''),
),
'fields'=>array(..),
));
Fields "date_from" and "date_to" in the table do not exist, both these filters search in the "date" field