Javascript Yii+;datepicker boostrap如何更新网格
我有以下问题。我有一个城市,我想放两个盒子,日期(从到)。当选择一段时间时,我想更新网格,但问题就在这里。这是到目前为止我的代码Javascript Yii+;datepicker boostrap如何更新网格,javascript,php,gridview,yii,datepicker,Javascript,Php,Gridview,Yii,Datepicker,我有以下问题。我有一个城市,我想放两个盒子,日期(从到)。当选择一段时间时,我想更新网格,但问题就在这里。这是到目前为止我的代码 $dateisOn = CHtml::textField('Event[from_date]', '', array('id' => 'from', 'data-date-format' => 'yyyy-mm-dd')) . ' До ' . CHtml::textField('Event[from_date]', '', a
$dateisOn = CHtml::textField('Event[from_date]', '',
array('id' => 'from', 'data-date-format' => 'yyyy-mm-dd')) .
' До ' . CHtml::textField('Event[from_date]', '',
array('id' => 'to', 'data-date-format' => 'yyyy-mm-dd'));
$this->widget('ext.widgets.StyledGridWidget', array(
'id' => 'event-grid',
'dataProvider' => $model->search(),
'enablePagination' => false,
'filter' => $model,
'columns' => array(
array(
'name' => 'product_id',
'value' => '$data->product_id'
),
array(
'name' => 'cnt',
'header' => 'Брой',
'value' => '$data->cnt'
),
array(
'name' => 'code',
'value' => '$data->code'
),
array(
'name' => 'date',
'filter' => $dateisOn,
),
),
)))
以下是js日期选择器:
var checkin = $('#from').datepicker({
onRender: function(date) {
}
}).on('changeDate', function(ev) {
var newDate = new Date(ev.date);
newDate.setDate(newDate.getDate() + 1);
checkout.setValue(newDate);
checkin.hide();
$('#to')[0].focus();
}).data('datepicker');
var checkout = $('#to').datepicker({
onRender: function(date) {
}
}).on('changeDate', function(ev) {
checkout.hide();
}).data('datepicker');
这是我的模型函数搜索
public function search() {
//var_dump($this->date_first); exit;
$criteria = new CDbCriteria;
$criteria->with = (array('order', 'product'));
$criteria->compare('product.id', $this->product_id);
$criteria->compare('product.code', $this->code);
$criteria->compare('cnt', $this->cnt);
$criteria->select = 'count(t.product_id) AS cnt, t.product_id, product.code';
$criteria->order = 'cnt DESC';
$criteria->group='t.product_id';
$criteria->limit = 10;
if (!empty($this->from_date) && empty($this->to_date)) {
$criteria->condition = "order.updated_at >= '$this->from_date'";
} elseif (!empty($this->to_date) && empty($this->from_date)) {
$criteria->condition = "order.updated_at <= '$this->to_date'";
} elseif (!empty($this->to_date) && !empty($this->from_date)) {
$criteria->condition = "order.updated_at >= '$this->from_date' and order.updated_at <= '$this->to_date'";
}
$criteria->together = true;
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
公共函数搜索(){
//变量转储($this->date\u first);退出;
$criteria=新的CDB标准;
$criteria->with=(数组('order','product');
$criteria->compare('product.id',$this->product\u id);
$criteria->compare('product.code',$this->code);
$criteria->compare('cnt',$this->cnt);
$criteria->select='将(t.product_id)计数为cnt、t.product_id、product.code';
$criteria->order='cnt DESC';
$criteria->group='t.product_id';
$criteria->limit=10;
如果(!empty($this->from_date)&&empty($this->to_date)){
$criteria->condition=“order.updated\u at>=”$this->from\u date';
}elseif(!empty($this->to_date)和&empty($this->from_date)){
$criteria->condition=“order.updated_at=”$this->from_date”和order.updated_at首先,您应该修复to_date
字段:
$dateisOn = CHtml::textField('Event[from_date]', '',
array('id' => 'from', 'data-date-format' => 'yyyy-mm-dd')) .
' До ' . CHtml::textField('Event[to_date]', '',
array('id' => 'to', 'data-date-format' => 'yyyy-mm-dd'));
您也可以修改搜索功能,只需使用:
$criteria->compare('order.updated_at', '>='.$this->from_date);
$criteria->compare('order.updated_at', '<='.$this->to_date);
$criteria->compare('order.updated_at','>='.$this->from_date);
$criteria->compare('order.updated_at','