我有图片和Cgridview
所示的搜索表单,以便在与...相同的页面中显示检索到的数据。
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-record-grid',
'dataProvider'=>$dataProviderRegSum,
'enableSorting' => false,
//'enablePagination'=>false,
'itemsCssClass'=>'tabchin',
'columns'=>
array(
array('header'=>'html',
'id'=>'autoId',
'class'=>'CCheckBoxColumn',
'selectableRows' => '50',
'headerTemplate'=>'<label>Select All{item}<span></span></label>',
'value'=>'$data["familyid"].",".$data["PersonID"].",".$data["PaymentStatus"].",".$data["RegistrationStatus"].",".$data["SignUpCode"].",".$data["firstname"].",".$data["lastname"].",".$data["PaymentTxnDate"].",".$data["ChoiceCode"].",".$data["ChoiceLabel"].",".$data["ClassAssignment"]
.",".$data["CreatedDate"].",".$data["Gender"].",".$data["age"].",".$data["schoolgrade"].",".$data["primarypersonid"].",".$data["PrimaryParentFirstName"].",".$data["PrimaryParentLastName"].",".str_replace(",",":",$data["primaryEmail"])
.",".$data["SessionAssignment"].",".$data["SubClassAssignment"].",".$data["Reconcile"]',
'htmlOptions'=>array("width"=>"40px;","align"=>"center"),
),
array(
'name'=>'PaymentDate',
'header'=>'Payment Date',
'value'=>'$data["PaymentTxnDate"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px","align"=>"left"),
),
array(
'header'=>'Family ID',
'name'=>'RegistrationID',
'value' => 'CHtml::link($data["familyid"], Yii::app() ->createUrl("registration/familyregview",array("id"=>$data["familyid"])),array("class"=>"regfamily"))',
'htmlOptions'=>array('style'=>'width:50px;text-align:center;'),
'type' => 'raw',
),
array(
'name'=>'PersonID',
'header'=>'Person ID',
'value'=>'$data["PersonID"].CHtml::hiddenField("Reg[]",$data["PersonID"])',
'type'=>'raw',
'htmlOptions'=>array("width"=>"50px;","align"=>"left"),
),
array(
'name'=>'FirstName',
'header'=>'First Name',
'value'=>'$data["firstname"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'LastName',
'header'=>'Family Name',
'value'=>'$data["lastname"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'Gender',
'header'=>'Gender',
'value'=>'$data["Gender"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"60px;","align"=>"left"),
),
array(
'name'=>'age',
'header'=>'Age',
'value'=>'$data["age"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"50px;","align"=>"left",'title'=>'Age Calculate by Program SatrtDate'),
),
array(
'name'=>'schoolgrade',
'header'=>'School Grade',
'value'=>'$data["schoolgrade"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'primarypersonid',
'header'=>'Primary Person ID',
'value'=>'$data["primarypersonid"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'PrimaryParentFirstName',
'header'=>'Primary First Name',
'value'=>'$data["PrimaryParentFirstName"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'PrimaryParentLastName',
'header'=>'Primary Last Name',
'value'=>'$data["PrimaryParentLastName"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'primaryEmail',
'header'=>'E-Mail',
'value'=>'$data["primaryEmail"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"100px;","align"=>"left"),
),
array(
'name'=>'Reconcile',
'header'=>'Reconcile',
'value'=>'$data["Reconcile"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"40px;","align"=>"left"),
),
//primaryEmail
array(
'header'=>'Payment',
'name'=>'Payemnt',
'value' => 'CHtml::link(CHtml::image("img/payment_history.png", "Delete", array("title"=>"Payment History","style"=>"width:32px;height:32px;")),
Yii::app() ->createUrl("registration/paymentregview",array("id"=>$data["familyid"])),array("class"=>"regpay"))',
'htmlOptions'=>array('style'=>'width:50px;text-align:center;'),
'type' => 'raw',
),
array(
'name'=>'CreatedDate',
'header'=>'Date Created',
'value'=>'$data["CreatedDate"]',
'type'=>'raw',
'htmlOptions'=>array("width"=>"80px;","align"=>"left"),
),
),
));
我想再清楚一下
所以我有图片中显示的搜索表单和同一页面中的Cgridview
。
单击搜索按钮时,应检索数据并显示带有分页的cgridview
。如何实现?请帮帮我。
我已将按钮代码提交为
$count = Yii::app()->db->createCommand('SELECT COUNT(familyid) FROM (' . $sql2 . ') as count_alias')->queryScalar();
$rawData = Yii::app()->db->createCommand($sql2);
$dataProviderRegSum = new CSqlDataProvider($rawData, array(
'keyField' => 'familyid',
//'pagination'=>false,
/* 'pagination' => array(
'pageSize' => Yii::app()->user->getState( 'pageSize', Yii::app()->params[ 'defaultPageSize' ] ),PaymentTxnDate
), */
'totalItemCount' => $count,
/* 'sort'=>array(
//'defaultOrder' => 'CreatedDate desc',
'defaultOrder' => 'PaymentTxnDate asc',
'attributes'=>array(
'RegistrationID'=>array(
'asc'=>'familyid',
'desc'=>'familyid DESC',
),
'FirstName'=>array(
'asc'=>'firstname',
'desc'=>'firstname DESC',
),
'LastName'=>array(
'asc'=>'lastname',
'desc'=>'lastname DESC',
),
'CreatedDate'=>array(
'asc'=>'CreatedDate',
'desc'=>'CreatedDate DESC',
),
'EmailedDate'=>array(
'asc'=>'EamiledDate',
'desc'=>'EamiledDate DESC',
),
),),
*/ 'pagination'=>array('pageSize'=>20)
));
此处$sql2
是我的查询。
如何将此$dataProviderRegSum
传递给同一视图,并在cgridview
中显示分页。
答案 0 :(得分:0)
我会举一个例子。试试这种方式。愿这对你有帮助。
在视图中,
<div class="page-content">
<div class="container">
<div class="row">
<div class="col-sm-3 pull-right"> <br>
<input type="text" id="search" class="form-control" placeholder="Search..."><br>
</div>
</div>
<div class="row">
<div class="col-md-12">
<?php
/**
* Listing of all employees
*/
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'employee-grid',
'dataProvider' => $model->search(),
'selectableRows' => 1,
'ajaxUpdate' => true,
'hideHeader' => false,
'template' => "{items}\n{pager}",
'enableHistory' => false,
'enableSorting' => false,
'cssFile' => Yii::app()->baseUrl . '/css/grid.css',
'htmlOptions' => array('class' => 'grid-view table-responsive'),
'columns' => array(
array(
'header' => 'Sl.No.',
'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
'htmlOptions' => array('width' => '5%'),
),
array(
'header' => 'Employee Code',
'value' => '$data->employeecode',
),
array(
'header' => 'Employee Name',
'value' => '$data->firstname." ".$data->lastname',
),
array(
'header' => 'Department',
'value' => '$data->department->department_name',
),
array(
'header' => 'Designation',
'value' => '$data->designation->designation_name',
),
array(
'header' => 'Email',
'value' => '$data->email',
),
array('class' => 'CButtonColumn',
'header' => 'Manage',
'template' => ' {view} {delete}',
'htmlOptions' => array('width' => '10%'),
'buttons' => array(
'view' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-eye-open'),
),
'delete' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-remove'),
),
),
),
),
));
?>
</div>
</div>
</div>
<script>
$("input").keyup(function () {
$('#employee-grid').yiiGridView('update', {
data: {search: $('#search').val()}
});
return false;
});
</script>
在模型更改搜索功能中,
public function search() {
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->order = 'staffid DESC';
$financialyear = Financialyear::model()->findByAttributes(array('status' => '1')); //! $financialyear stores activated financial year details
$searchterm = empty($searchterm) ? trim(Yii::app()->request->getParam('search')) : $searchterm;
$criteria->with = array('department', 'designation');
$searchterm = htmlspecialchars($searchterm, ENT_QUOTES);
if (!empty($searchterm)) {
$criteria->addCondition(' t.employeecode like "' . $searchterm . '%" OR
t.firstname like "' . $searchterm . '%" OR
t.email like "' . $searchterm . '%" OR
designation.designation_name like "' . $searchterm . '%" OR
department.department_name like "' . $searchterm . '%" AND
t.status = "0" ');
} else {
$criteria->condition = 't.status = "0"';
}
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pagesize' => 25,
)
));
}
这段代码很适合我。所以请仔细阅读。