Skip to content

Commit

Permalink
Perbaiki urut data tabel, termasuk pergi ke halaman pertama.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddieridwan committed Feb 28, 2021
1 parent b46cc4a commit 378a896
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
25 changes: 16 additions & 9 deletions donjo-app/models/Penduduk_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,10 @@ private function list_data_sql()
$this->hamil_sql(); // Filter blum digunakan
}

// $limit = 0 mengambil semua
public function list_data($order_by = 1, $offset = 0, $limit = 0)
// Perlu di urut sebelum paging dan sesudah paging
private function order_by_list($order_by)
{
//Main Query
$this->list_data_sql();

//Ordering SQL
//Urut data
switch ($order_by)
{
case 1: $this->db->order_by('u.nik'); break;
Expand All @@ -369,12 +366,21 @@ public function list_data($order_by = 1, $offset = 0, $limit = 0)
case 6: $this->db->order_by('d.no_kk DESC, u.kk_level'); break;
case 7: $this->db->order_by('umur'); break;
case 8: $this->db->order_by('umur', 'DESC'); break;
case 9: $this->db->order_by('created_at'); break;
case 10: $this->db->order_by('created_at', 'DESC'); break;
case 9: $this->db->order_by('u.created_at'); break;
case 10: $this->db->order_by('u.created_at', 'DESC'); break;
case 11: $this->db->order_by('log.tgl_peristiwa'); break;
case 12: $this->db->order_by('log.tgl_peristiwa', 'DESC'); break;
default: $this->db->order_by('CONCAT(d.no_kk, u.kk_level)');
}
}

// $limit = 0 mengambil semua
public function list_data($order_by = 1, $offset = 0, $limit = 0)
{
//Main Query
$this->list_data_sql();
$this->db->select("(DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(u.tanggallahir)), '%Y')+0) AS umur");
$this->order_by_list($order_by);

//Paging SQL
if ($limit > 0 ) $this->db->limit($limit, $offset);
Expand All @@ -395,9 +401,10 @@ public function list_data($order_by = 1, $offset = 0, $limit = 0)
(DATE_FORMAT(FROM_DAYS(TO_DAYS(log.tgl_peristiwa)-TO_DAYS(u.tanggallahir)), '%Y')+0) AS umur_pada_peristiwa,
x.nama AS sex, sd.nama AS pendidikan_sedang, n.nama AS pendidikan, p.nama AS pekerjaan, g.nama AS agama, m.nama AS gol_darah, hub.nama AS hubungan, b.no_kk AS no_rtm, b.id AS id_rtm
");

$this->db->from("($query_dasar) as u");
$this->lookup_ref_penduduk();
$this->tahun_bulan();
$this->order_by_list($order_by);

$data = $this->db->get()->result_array();

Expand Down
2 changes: 1 addition & 1 deletion donjo-app/views/global/paging.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<div class="col-sm-9 dataTables_paginate">
<ul class="pagination">
<?php if ($paging->start_link): ?>
<li <?= jecho($paging->page, 1, "class='disabled'"); ?>><a href="<?= ($func == 'index') ? site_url("$this->controller") : site_url("$this->controller/$func"); jecho($paging->page.'!', 1, "#"); ?>" aria-label="First"><span aria-hidden="true">Awal</span></a></li>
<li <?= jecho($paging->page, 1, "class='disabled'"); ?>><a href="<?= site_url("$this->controller/$func/1/$o"); jecho($paging->page.'!', 1, "#"); ?>" aria-label="First"><span aria-hidden="true">Awal</span></a></li>
<?php endif; ?>
<?php if ($paging->prev): ?>
<li><a href="<?= site_url("$this->controller/$func/$paging->prev/$o"); ?>" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
Expand Down
12 changes: 6 additions & 6 deletions donjo-app/views/sid/kependudukan/penduduk.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@
<th>No</th>
<th>Aksi</th>
<th>Foto</th>
<th><?= url_order($o, "{$this->controller}/{$func}/$p", 1, 'NIK'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/1", 1, 'NIK'); ?></th>
<th>Tag ID Card</th>
<th><?= url_order($o, "{$this->controller}/{$func}/$p", 3, 'Nama'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/$p", 5, 'No. KK'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/1", 3, 'Nama'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/1", 5, 'No. KK'); ?></th>
<!-- tambah kolom orang tua-->
<th>Nama Ayah</th>
<th>Nama Ibu</th>
Expand All @@ -178,11 +178,11 @@
<th>RW</th>
<th>RT</th>
<th>Pendidikan dalam KK</th>
<th><?= url_order($o, "{$this->controller}/{$func}/$p", 7, 'Umur'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/1", 7, 'Umur'); ?></th>
<th >Pekerjaan</th>
<th>Kawin</th>
<th><?= url_order($o, "{$this->controller}/{$func}/$p", 11, 'Tgl Peristiwa'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/$p", 9, 'Tgl Terdaftar'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/1", 11, 'Tgl Peristiwa'); ?></th>
<th><?= url_order($o, "{$this->controller}/{$func}/1", 9, 'Tgl Terdaftar'); ?></th>
</tr>
</thead>
<tbody>
Expand Down

0 comments on commit 378a896

Please sign in to comment.