【问题标题】:Yii+datepicker boostrap how update gridYii+datepicker bootstrap 如何更新网格
【发布时间】:2014-04-05 14:35:24
【问题描述】:

我有以下问题。我有一个城市,我想放两个日期(从-到)。在选择一段时间时,我想更新网格,但这是问题。到目前为止,这是我的代码

$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,
    ));
}

【问题讨论】:

    标签: javascript php gridview yii datepicker


    【解决方案1】:

    首先,您应该修复 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);  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 2018-06-21
      相关资源
      最近更新 更多