Berikut ini adalah tutorial cara membuat pagination bootsrapt.
- Controller
$array = array('ProjectCode' => $ProjectCode);
$transaksi = new M_finance();
$data['acc_transaction'] = $transaksi->report_transaction_limit($array, $TransactionDate1, $TransactionDate2);
$data['pager'] = $transaksi->pager;
$data['page'] = $this->request->getVar('page_data') ? $this->request->getVar('page_data') : 1;
- Model
protected $table = 'acc_transaction';
protected $primaryKey = 'TransactionNo';
protected $returnType = 'object';
function report_transaction_limit($array, $TransactionDate1, $TransactionDate2)
{
return $this->select()
->where($array)
->where('TransactionDate BETWEEN "'. $TransactionDate1. '" and "'. $TransactionDate2.'"')
->paginate(5, 'data');
// return $this->select()->join('tbl_category', 'tbl_news.category_id = tbl_category.category_id')->paginate($nb_page); // Jika menggunakan join query
}
- View
<table class="tb1" cellpadding="5" width="100%">
<thead>
<tr>
<th>No</th>
<th>No BPK</th>
<th>Tanggal</th>
</tr>
</thead>
<tbody>
<?php
$no=1+(5*($page-1));
foreach($acc_transaction as $row5):
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $row5->TransactionNo; ?></td>
<td><?php echo $row5->TransactionDate; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $pager->links('data', 'bootstrap_pagination'); ?>
- app/Config/Pager.php
public $templates = [
'default_full' => 'CodeIgniter\Pager\Views\default_full',
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
'default_head' => 'CodeIgniter\Pager\Views\default_head',
'bootstrap_pagination' => 'App\Views\pagers\bootstrap_pagination', // Custom Pagination
];
- app/Views/pagers/bootstrap_pagination.php
<?php $pager->setSurroundCount(2) ?>
<br />
<nav aria-label="Page navigation">
<ul class="pagination">
<?php if ($pager->hasPrevious()) : ?>
<li class="page-item">
<a class="page-link" href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first') ?>">
<span aria-hidden="true"><?= lang('Pager.first') ?></span>
</a>
</li>
<li class="page-item">
<a class="page-link" href="<?= $pager->getPrevious() ?>" aria-label="<?= lang('Pager.previous') ?>">
<span aria-hidden="true"><?= lang('Pager.previous') ?></span>
</a>
</li>
<?php endif ?>
<?php foreach ($pager->links() as $link) : ?>
<li class="page-item <?= $link['active'] ? 'active"' : '' ?>">
<a class="page-link" href="<?= $link['uri'] ?>">
<?= $link['title'] ?>
</a>
</li>
<?php endforeach ?>
<?php if ($pager->hasNext()) : ?>
<li class="page-item">
<a class="page-link" href="<?= $pager->getNext() ?>" aria-label="<?= lang('Pager.next') ?>">
<span aria-hidden="true"><?= lang('Pager.next') ?></span>
</a>
</li>
<li class="page-item">
<a class="page-link" href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last') ?>">
<span aria-hidden="true"><?= lang('Pager.last') ?></span>
</a>
</li>
<?php endif ?>
</ul>
</nav>