【发布时间】:2017-08-20 00:27:55
【问题描述】:
我正在使用 Yii 应用程序。在那如何给表格内容分页(不使用cgridview)。
在视图中,
<table data-provides="rowlink" data-page-size="20" data-filter="#mailbox_search" class="table toggle-square default footable-loaded footable line-content" id="mailbox_table">
<thead>
<tr>
<th></th>
<th data-hide="phone,tablet">From</th>
<th>Subject</th>
<th data-hide="phone" class="footable-last-column">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($model as $item) {
if ($item->fromuser->usertypeid === '0') {
$name = $item->fromuser->username;
} else if ($item->fromuser->usertypeid === '1') {
$student = Student::model()->findByPk($item->fromuser->userid);
$name = $student->student_admissionno . " - " . $student->student_firstname . " " . $student->student_middlename . " " . $student->student_lastname;
} else if ($item->fromuser->usertypeid === '3') {
$guardian = Guardian::model()->findByPk($item->fromuser->userid);
$name = $guardian->guardian_name;
} else {
$employee = Employeemaster::model()->findByPk($item->fromuser->userid);
$name = $employee->employee_code . " - " . $employee->employee_firstname . " " . $employee->employee_middlename . " " . $employee->employee_lastname;
}
if ($item->email_status == 1)
echo '<tr id="' . $item->emailid . '" class="unreaded rowlink" style="display: table-row;">';
else
echo '<tr id="' . $item->emailid . '" class="rowlink" style="display: table-row;">';
echo '<td class="nolink footable-first-column">';
echo '<span class="footable-toggle"></span>';
echo '<input type="checkbox" class="mbox_msg_select" name="msg_sel"></td>';
echo '</span></td>';
echo '<td>' . $name . '</td>';
echo '<td>' . $item->email_subject . '</td>';
$originalDate = $item->time;
$newDate = date("Y-M-d H:i:s", strtotime($originalDate));
echo '<td class="footable-last-column">' . $newDate . '</td></tr>';
}
?>
</tbody>
</table>
<div class="main-detail-con" style="width:700px;">
<div style="width:700px; padding-left: 0px;" class="listing-center-numbers">
<?php
$this->widget('CLinkPager', array(
'pages' => $pages,
'currentPage' => $pages->getCurrentPage(),
'itemCount' => $item_count,
'pageSize' => $page_size,
'maxButtonCount' => 5,
));
?>
</div>
</div>
<div class="clear"></div>
在控制器中,
public function actionEmail() {
$criteria = new CDbCriteria;
$criteria->order = 'time DESC';
$criteria->condition = 'to_userid = :id';
$criteria->params = array(':id' => Yii::app()->user->id);
$criteria->addCondition('t.email_status= "2" OR
t.email_status= "1"');
$item_count = Email::model()->count($criteria);
$model = Email::model()->findAll($criteria);
$pages = new CPagination($item_count);
$pages->setPageSize(Yii::app()->params['listPerPage']);
$pages->applyLimit($criteria);
$this->render('inbox', array(
'model' => $model,
'item_count' => $item_count,
'page_size' => Yii::app()->params['listPerPage'],
'items_count' => $item_count,
'pages' => $pages,
));
}
在 main/config.php 中
'params' => array(
'listPerPage'=> 2,//default pagination size
),
输出是,
页面大小(我给每页 2 个)使用此代码不起作用。请帮帮我...
【问题讨论】:
-
你可以使用 simplepagination.js 参考 uibox.in/item/146 的例子
标签: php yii pagination html-table