/* Filtering operation */
if($filter !=null){
if(!$filter[0]['isComplex']){
$where= whereFilter($filter[0]);
}
else{
$where = performFiltering($filter[0]['predicates']);
}
if($searchQuery!= null){
$query = $query. " AND (" .$where. ")";
}
else{
$query = $query. " WHERE " .$where;
}
$sql= $query;
}
function performFiltering($filter){
$temp;
$value;
foreach ($filter as $v) {
if(!$v['isComplex']){
$temp= whereFilter($v);
$value= processFilterQuery($temp);
}
else
{
performFiltering($v['predicates']);
}
}
return $value;
}
function processFilterQuery($temp){
global $filterQuery;
if($filterQuery != null){
$filterQuery =$filterQuery." AND ". $temp;
}
else{
$filterQuery = $temp;
}
return $filterQuery;
}
|
function whereFilter($filter){
$field = $filter['field'];
$operator = $filter['operator'];
$value = $filter['value'];
$ignorecase = $filter['ignoreCase'];
$iscomplex = $filter['isComplex'];
//Map operators
$fltrOp= MapOperator($operator,$value);
return $field. " ".$fltrOp;
}
function MapOperator($op,$value){
$operater;
switch ($op)
{
case "greaterthan":
$operater = ">";
break;
..
/* String Operators */
case "startswith":
return "LIKE '" .$value."%'";
..
}
return $operater." '".$value."'"; //returning operators with values
}
|
header("Content-type:application/json");
$link = mysqli_connect('localhost', 'root', '', 'mysql');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$skip = $_GET['$skip'];
$take = $_GET['$top'];
$sort = $_GET['$orderby'];
$query = "SELECT * FROM help_category";
if($sort !=null)
{
$query = $query." ORDER BY " .$sort; //perform sort operation
}
if($take!=null){
$query = $query." limit ".$skip.",".$take; //perform skip and take operation
}
$result = mysqli_query($link,$query);
$json=array();
while ($row = mysqli_fetch_array($result)) {
array_push($json,array(
'help_category_id' => $row{'help_category_id'},
'name' => $row{'name'},
'parent_category_id' => $row{'parent_category_id'},
));
}
$countquery = mysqli_query($link,"SELECT * FROM help_category");
$count=mysqli_num_rows($countquery); //return total records count
$response=array("result"=>$json,"count"=>(int)$count);
echo json_encode($response);
if(function_exists($_GET['action'])) {
$_GET['action']();
}
|
/* Searching operation */
if($search !=null){
$fields = $search[0]['fields'];
$key = $search[0]['key'];
$columncount = count($fields);
$searchQuery;
for($i = 0; $i <= $columncount-1; $i++){
$svalue = $fields[$i];
if($i>0){
$searchQuery =$searchQuery." OR ". $svalue." LIKE '%" .$key. "%'";
}
else{
$searchQuery = $svalue. " LIKE '%" .$key. "%'";
}
}
$query = $query. " WHERE " .$searchQuery ;
$sql= $query;
} |
$sort = $_GET['$orderby'];
$query = "SELECT * FROM help_category";
if($sort !=null)
{
$query = $query." ORDER BY " .$sort; //perform sort operation
}
if($take!=null){
$query = $query." limit ".$skip.",".$take; //perform skip and take operation
}
$result = mysqli_query($link,$query);
. . . .
$response=array("result"=>$json,"count"=>(int)$count);
echo json_encode($response);
}
|
if($filter !=null){
if(!$filter[0]['isComplex']){
$where= whereFilter($filter[0]);
}
else{
$where = performFiltering($filter[0]['predicates'],$filter['condition']);
}
$searchQuery = isset($searchQuery) ? $searchQuery : NULL;
if( $searchQuery != null){
$query = $query. " AND (" .$where. ")";
}
else{
$query = $query. " WHERE " .$where;
}
$sql= $query;
}
function performFiltering($filter,$cond){
$temp;
$value;
foreach ($filter as $v) {
if(!$v['isComplex']){
$temp= whereFilter($v);
$value= processFilterQuery($temp,$cond);
}
else
{
performFiltering($v['predicates'],$cond);
}
}
function processFilterQuery($temp,$cond){
global $filterQuery;
$con = isset($cond) ? $cond : NULL ;
$cond = isset($cond)== "and" ? " AND " : " OR ";
if($filterQuery != null){
$filterQuery =$filterQuery.$cond.$temp;
}
else{
$filterQuery = $temp;
}
return $filterQuery;
}
|
<?php
$col1 = new EJ\Grid\Column();
$col1->field("help_topic_id")->headerText("OrderID")->isPrimaryKey(true)->textAlign("right")->width(100);
$col2 = new EJ\Grid\Column();
$col2->field("name")->headerText("CustomerID")->width(70);
$col3 = new EJ\Grid\Column();
$col3->field("help_category_id")->headerText("EmployeeID")->textAlign("right")->width(70);
$toolbarItems = array("add","edit","delete","update","cancel");
$edit =new EJ\Grid\EditSetting();
$page = new EJ\Grid\PageSetting();
$toolbar= new EJ\Grid\ToolbarSetting();
echo $grid -> dataSource($dataManager)->columns($gridColumns)->allowPaging(true)->allowMultiSorting(true)->editSettings($edit->allowEditing(true)->allowDeleting(true)->allowAdding(true))->toolbarSettings($toolbar->showToolbar(true)->toolbarItems($toolbarItems))->childGrid($child)->allowSorting(true)->allowFiltering(true)->render();
?>
Serverside:-
$filterQuery = NULL;
$skip = $params['skip'];
$take = $params['take'];
$search = isset($params['search']) ? $params['search'] : NULL ;
$filter = isset($params['where']) ? $params['where'] : NULL ;
$sort = isset($params['sorted']) ? $params['sorted'] : NuLL ;
$query =$sql = "SELECT * FROM help_topic";
/* Sorting operation */
if($sort !=null)
{
$fields = $sort[0]['fields'];
$columncount = count($fields);
$sortQuery;
for($i = 0; $i <= $columncount-1; $i++){
if($sort[i]['direction'] == "descending"){
$sortQuery = $sortQuery." ORDER BY " .$sort[i]['name']. " desc";
}
else{
$sortQuery = $sortQuery." ORDER BY " .$sort[i]['name']; //perform sort operation
}
}
$query = $sortQuery;
$sql= $query;
}
if($take!=null){
$query = $query." limit ".$skip.",".$take; //perform skip and take operation
}
$result = mysqli_query($link,$query);
$json=array();
while ($row = mysqli_fetch_array($result)) {
array_push($json,array(
'help_topic_id' => $row{'help_topic_id'},
'name' => $row{'name'},
'help_category_id' => $row{'help_category_id'},
));
}
$countquery = mysqli_query($link,$sql);
$count=mysqli_num_rows($countquery); //return total records count
$response=array("result"=>$json,"count"=>(int)$count);
} |