[eluser]cestaz18[/eluser]
VIEW
Code:
<div id="List" class="panel" style="display:block">
<div class="content">
<div class="dpane">
<table id="listFlex" class="listFlex" cellpadding="0" cellspacing="0"></table>
<div id="pager2" class="scroll" style="text-align: center;"></div>
</div>
</div>
</div>
Application/views/template -- TABLE.php
Code:
<?
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
$this->output->set_header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
$this->output->set_header("Cache-Control: no-cache, must-revalidate" );
$this->output->set_header("Pragma: no-cache" );
$this->output->set_header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $totalpages,\n";
$json .= "records: $totalrecords,\n";
$json .= "rows: ";
$rows = array();
if (isset($db)) {
foreach($db->result_array() as $row):
$key = key($row);
$id = $row[$key];
unset($row[$key]);
$cell = array();
foreach ($row as $item)
{
$cell[] = $item;
}
$rows[] = array(
"id" => $id,
"cell" => $cell
);
endforeach;
}
$json .= json_encode($rows);
if (isset($moredata))
$json .= ",".json_encode(array('moredata'=>$moredata));
$json .= "\n";
$json .= "}";
echo $json;
?>
CONTROLLER
Code:
function listview()
{
$data = $this->Sec_role_db->getList();
$this->load->view('template/table',$data);
}
MODEL
Code:
function getList()
{
$page = $this->input->post('page');
$limit = $this->input->post('rows'); // get how many rows we want to have into the grid
$sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
$sord = $this->input->post('sord'); // get the direction
$query = $this->input->post('query');
$qtype = $this->input->post('qtype');
if (!$sidx) $sidx = 'role_id';
if (!$sord) $sord = 'asc';
if (!$page) $page = 1;
if (!$limit) $limit = 25;
//$start = (($page-1) * $limit);
$this->db->start_cache();
if ($qtype == 'role_code' && $query) $this->db->like('role_code', $query);
if ($qtype == 'role_code' && $query) $this->db->like('role_desc', $query);
// calculate the number of rows for the query. We need this for paging the result
$this->db->from('sec_role');
$this->db->where('sec_role.is_deleted','0');
$count = $this->db->count_all_results(); //code added by cess
//$row = $this->db->count_all_results(); //code added by cess
//$count = $row['count'];
// calculate the total pages for the query - code added by cess
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page - code added by cess
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $limit * $page - $limit; // do not put $limit*($page - 1)
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
$this->db->select("role_id as pkey,role_id, role_code, role_desc");
$this->db->order_by($sidx,$sord);
$this->db->limit($limit, $start);
$query = $this->db->get("sec_role");
$this->db->flush_cache();
$data['db'] = $query;
$data['page'] = $page;
$data['totalpages'] = $total_pages;//code added by cess^^
$data['totalrecords']=$count; //- code added by cess
return $data;
}