Just to announce that my integration of Flexigrid with CodeIgniter is ready.
You can see/download it here:
http://flexigrid.eyeviewdesign.com/
Any suggestions / bugs / whatever mail me.
NOTE: I just started to work with Ajax/Jquery so bare with me.
Hope you like it.
Wow your fingers must be burning! How long did it take you to code that? Kudos!
I admit my implementation is a hack. I don’t have all the error checking. But if someone wants to see it, it is a little shorter and uses Lovable ReST.
View file ajax_results.php;
ps. add the < > on the ends of the src file lines (they get stripped out if I don’t mess em up.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/css/flexigrid/flexigrid.css"/>
script type="text/javascript" src="/javascript/jquery.js"> script
script type="text/javascript" src="/javascript/jquery.js"> script
</table>
$('.emp_table').flexigrid
(
{
url: 'http://www.someurl.com/CI/index.php/ajax_emp/jason/function/test',
dataType: 'json',
sortname: "Last_Name",
sortorder: "asc",
colModel : [
{display: 'Id', name : 'Emp_Id', width : 40, sortable : true, align: 'center'},
{display: 'Frist Name', name : 'First_Name', width : 75, sortable : true, align: 'left'},
{display: 'Last Name', name : 'Last_Name', width : 80, sortable : true, align: 'left'},
{display: 'Phone Number', name : 'Phone_Number', width : 80, sortable : false, align: 'left'},
{display: 'Cell Number', name : 'Cell_Phone', width : 80, sortable : false, align: 'left'},
{display: 'Email', name : 'Email', width : 200, sortable : false, align: 'left'}
],
title: 'Employee Search Results',
usepager: true,
useRp: true,
rp: 10,
width: 700,
height: 200
}
);
</body>
</html>
Controller Ajax_emp;
<?php
class Ajax_emp extends Controller {
function Ajax_emp()
{
parent::Controller();
$this->load->library('rest');
}
function _search($data)
{
$rp=(int)$data->rp;
$page=(int)$data->page;
$start = (($page-1) * $rp);
$limit = "LIMIT $start, $rp";
$sortname=$data->sortname;
$sortorder=$data->sortorder;
$q="SELECT SQL_CALC_FOUND_ROWS id, Emp_Id, First_Name, Last_Name, Phone_Number, Cell_Phone, Email FROM emp_table ORDER BY $sortname $sortorder $limit";
$emprows = $this->db->query($q);
$totalrows = $this->db->query('SELECT FOUND_ROWS();');
$totalrows = $totalrows->row_array();
$totalrows = array_shift($totalrows);
$outresult = "";
$outresult .= "{\n";
$outresult .= "page:$page,\n";
$outresult .= "total:$totalrows,\n";
$outresult .= "rows:[";
$rc=false;
foreach ($emprows->result() as $row )
{
if($rc) $outresult .=",";
$id=$row->id;
$outresult .="\n";
$outresult .="{id:'$row->id"."',cell:['".$row->Emp_Id."','".addslashes($row->First_Name)."','".addslashes($row->Last_Name)."'";
$outresult .=",'".$row->Phone_Number."','".$row->Cell_Phone."','".$row->Email."'";
$outresult .="]}";
$rc = true;
}
$outresult .="]\n";
$outresult .="}";
echo $outresult;
}
function jason()
{
$this->load->library('rest');
$this->rest->addFunction('test', '_search', 'post');
$this->rest->serve($this);
}
function ajax()
{
$data['heading'] = "Search";
$this->load->view('ajax_results',$data);
}
}
?>
PS. Paulo, Great Work 😊