I'm using Yii application. In that how to give pagination to a table contents (not using cgridview).
In view,
<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>
In Controller,
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,
));
}
In main/config.php
'params' => array(
'listPerPage'=> 2,//default pagination size
),
Output is,
The page size (I am giving 2 for per page) is not working by using this code. Please help me...
First of all define a new params in
config/main.php
, something like:Now, modify your controller's action like:
Then in your view after
foreach
loop add CLinkPager widget, like:Thats all you need to do, you might have to do some css changes though, hope that helps :)