Reputation: 27
i try to load data from database otomatis, input from phpmyadmin with query and otomatis data can show in view AJAX, then i try to join with pagination AJAX. this my code to show otomatis : model :
function get_all_transaksi_proses() {
$limit=10; $offset = 0;
$rs = $this->db->query("SELECT a.id_transaksi, a.nama, a.tgl_transaksi,
(SELECT COUNT( id_transaksi ) AS jum FROM tbl_detail_trs_menu WHERE id_transaksi = a.id_transaksi)
AS jumlah, a.status_transaksi, a.total, b.status_pelanggan, c.nama_karyawan FROM tbl_transaksi a LEFT JOIN
tbl_pelanggan b ON a.id_pelanggan = b.id_pelanggan LEFT JOIN tbl_karyawan c ON a.id_karyawan =
c.id_karyawan WHERE a.status_transaksi = 'PROSES' LIMIT ".$offset.",".$limit."");
return $rs;
}
control :
public function ambilDataTransaksi() {
$data=$data=$this->transaksi->get_all_transaksi_proses();
echo json_encode(array("result" => $data->result_array()));
}
view :
<script type="text/javascript">
$(document).ready(function() {
selesai();
});
function selesai() {
setTimeout(function() {
update();
selesai();
}, 200);
}
function update() {
$.getJSON("<?php echo base_url();?>transaksiDigorCont/ambilDataTransaksi", function(data) {
$(".dataku").empty();
$no=1;
$.each(data.result, function() {
$(".dataku").append(
"<tr><td>"+$no+"</td>\n\
<td>"+this['id_transaksi']+"</td>\n\
<td>"+this['nama']+"</td>\n\
<td>"+this['tgl_transaksi']+"</td>\n\
<td>"+this['jumlah']+"</td>\n\
<td>"+this['status_transaksi']+"</td>\n\
<td>"+this['total']+"</td>\n\
<td>"+this['status_pelanggan']+"</td>\n\
<td>"+this['nama_karyawan']+"</td><td>"+this['nama_karyawan']+"</td></tr>");
$no++;});
});
}
</script>
so why i implement pagination in this code... thx u
Upvotes: 0
Views: 720
Reputation: 404
In your controller add pagination library, logic create offset & limit, and load view of listing like wise... (Place normal pagination code here)
Write this jquery code on your view to load different pages :
<script>
$(function(){
$("#pagination-div-id a").click(function(){
$.ajax({
type: "POST",
url: $(this).attr("href"),
data:"q=<?php echo $searchString; ?>",
success: function(res){
$("#containerid").html(res);
}
});
return false;
});
});
</script>
like wise... You need to do some dig & dag over here.. But this way is working for me.
Here is one link for reference & detailed example : http://ellislab.com/forums/viewthread/122597/
Upvotes: 0