我在视图中使用了bootstrap.widgets.TbGridView 以下是截图: -
我想在我的日期过滤器中使用datepickder。 PLZ帮我怎么把这个>
以下是我的相同代码: -
$this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'type'=>'striped bordered condensed',
'pager' => array('htmlOptions'=>array('class'=>'pager',
'maxButtonCount' => 3)), // set whatever css class you want
'columns'=>array(
array(
'header'=>'Type',
'name'=>'sparktype_id',
'value'=>'sparktype::itemssparktypesname($data->sparktype_id)',
),
array(
'header'=>'Headline',
'name'=>'headline',
'type'=>'raw',
'value'=>'CHtml::link(CHtml::encode($data->headline), $data->url)',
),
array(
'header'=>'Date',
'name'=>'added_date',
'type'=>'date',
'value'=>'$data->added_date',
),
array(
'header'=>'State',
'name'=>'statemetro_id', 'value'=>'statemetro::itemstateforspark($data->sparkdetails[0]->statemetro_id)',
'type'=>'raw',
),array('class'=>'CButtonColumn',
'deleteConfirmation'=>'Are you sure you want to delete this Spark ?',
'htmlOptions'=>array('width'=>70),
),
),
));
答案 0 :(得分:0)
你可以实现这样的日期选择: -
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'filter' => $model,
'afterAjaxUpdate' => 'reinstallDatePicker',
'columns' => array(
...
array(
'header'=>'Date',
'name'=>'added_date',
'filter' => array(
'model' => $model,
'attribute' => 'added_date',
'htmlOptions' => array(
'id' => 'datepicker_for_added_date',
'size' => '10',
),
'defaultOptions' => array(
'shownOn' => 'focus',
'dateFormat' => 'yy-mm-dd', //Change your date format accordingly
//These are normal DatePicker options, omit unnecessary ones
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
),
...
然后在您的网页上写下此代码: -
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#datepicker_for_added_date').datepicker();
}
");
供参考,您可以参考此页: - http://www.yiiframework.com/wiki/318/using-cjuidatepicker-for-cgridview-filter/