I am a new programmer in code igniter.
I am trying to integrate jqgrkimlik with code igniter and after seven hours i came to a successful point where jqgrkimlik and code igniter is fully integrated with search option.
İlk başta, uygulama / model dizininde bir model yazın. Kod ......
class JqgrkimlikSample extends CI_Model {
function getAllData($start,$limit,$skimlikx,$sord,$where){
$this->db->select('kimlik,isim,E-posta,pasaport,telefon,faks,adres');
$this->db->limit($limit);
if($where != NULL)
$this->db->where($where,NULL,FALSE);
$this->db->order_by($skimlikx,$sord);
$query = $this->db->get('info',$limit,$start);
return $query->result();
}
}
Sonra, başvuru / denetleyici dizininde bir kontrolör yazmak. Kodudur
class Demo extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('JqgrkimlikSample');
}
function jqGrkimlik(){
$this->load->view('showGrkimlik');
}
function loadData(){
$page = isset($_POST['page'])?$_POST['page']:1;
$limit = isset($_POST['rows'])?$_POST['rows']:10;
$skimlikx = isset($_POST['skimlikx'])?$_POST['skimlikx']:'isim';
$sord = isset($_POST['sord'])?$_POST['sord']:'';
$start = $limit*$page - $limit;
$start = ($start<0)?0:$start;
$where = "";
$searchField = isset($_POST['searchField']) ? $_POST['searchField'] : false;
$searchOper = isset($_POST['searchOper']) ? $_POST['searchOper']: false;
$searchString = isset($_POST['searchString']) ? $_POST['searchString'] : false;
if ($_POST['_search'] == 'true') {
$ops = array(
'eq'=>'=',
'ne'=>'<>',
'lt'=>'<',
'le'=>'<=',
'gt'=>'>',
'ge'=>'>=',
'bw'=>'LIKE',
'bn'=>'NOT LIKE',
'in'=>'LIKE',
'ni'=>'NOT LIKE',
'ew'=>'LIKE',
'en'=>'NOT LIKE',
'cn'=>'LIKE',
'nc'=>'NOT LIKE'
);
foreach ($ops as $key=>$value){
if ($searchOper==$key) {
$ops = $value;
}
}
if($searchOper == 'eq' ) $searchString = $searchString;
if($searchOper == 'bw' || $searchOper == 'bn') $searchString .= '%';
if($searchOper == 'ew' || $searchOper == 'en' ) $searchString = '%'.$searchString;
if($searchOper == 'cn' || $searchOper == 'nc' || $searchOper == 'in' || $searchOper == 'ni') $searchString = '%'.$searchString.'%';
$where = "$searchField $ops '$searchString' ";
}
if(!$skimlikx)
$skimlikx =1;
$count = $this->db->count_all_results('info');
if( $count > 0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page=$total_pages;
$query = $this->JqgrkimlikSample->getAllData($start,$limit,$skimlikx,$sord,$where);
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
foreach($query as $row) {
$responce->rows[$i]['kimlik']=$row->kimlik;
$responce->rows[$i]['cell']=array($row->isim,$row->E-posta,$row->pasaport,$row->telefon,$row->faks,$row->adres);
$i++;
}
echo json_encode($responce);
}
}
Ve nihayet sizin application / views dizinine bir görünüm yazmak ..
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url()?>application/views/css/custom-theme/jquery-ui-1.8.16.custom.css" />
<link type="text/css" href="<?php echo base_url()?>application/views/css/ui.jqgrkimlik.css" rel="stylesheet" />
<link type="text/css" href="<?php echo base_url()?>application/views/css/plugins/searchFilter.css" rel="stylesheet" />
<style>
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script type="text/javascript" src="<?php echo base_url(); ?>application/views/js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>application/views/js/i18n/grkimlik.locale-en.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>application/views/js/jquery.jqGrkimlik.min.js"></script>
<title>Codeigniter With JQGrkimlik</title>
</head>
<body>
<center>
<h1>Codeigniter With JQGrkimlik</h1>
<?php
$ci =& get_instance();
$base_url = base_url();
?>
<table kimlik="list"></table><!--Grkimlik table-->
<div kimlik="pager"></div> <!--pagination div-->
</center>
</body>
<script type="text/javascript">
$(document).ready(function (){
jQuery("#list").jqGrkimlik({
url:'<?=$base_url.'index.php/demo/loadData'?>', //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Name','Email','Passport','Phone','Fax','Address'], //Grkimlik column headings
colModel:[
{isim:'isim',index:'isim', wkimlikth:100, align:"left"},
{isim:'E-posta',index:'E-posta', wkimlikth:150, align:"left"},
{isim:'pasaport',index:'pasaport', wkimlikth:100, align:"right"},
{isim:'telefon',index:'telefon', wkimlikth:100, align:"right"},
{isim:'faks',index:'faks', wkimlikth:100, align:"right"},
{isim:'adres',index:'adres', wkimlikth:100, align:"right"},
],
rowNum:10,
wkimlikth: 750,
//height: 300,
rowList:[10,20,30],
pager: '#pager',
sortisim: 'kimlik',
viewrecords: true,
rownumbers: true,
grkimlikview: true,
caption:"List Of Person"
}).navGrkimlik('#pager',{edit:false,add:false,del:false});
});
</script>
For the view file for myself i create two folder in views directory js and css.
and in js foder i place the jquery-1.5.2.min.js, grkimlik.locale-en.js(views/js/i18n/), jquery.jqGrkimlik.min.js which you find in jqgrkimlik package.
Jquery-ui-1.8.16.custom.css, ui.jqgrkimlik.css bir ihtiyaç Aynı şekilde de jqGrkimlik paketinde mevcut olduğunu.
tam süreci çalıştırmak için bir veritabanı adlandırılmış jqgrkimlik_sample oluşturmak zorunda ve veritabanında bilgi alanları içeren adında bir tablo oluşturun ...
kimlik
isim
E-posta
pasaport
telefon
faks
adres
thats it. keyfini çıkarın. güle güle.