<?php
require_once '../EJ/AutoLoad.php';
?>
<div class="cols-sample-area">
<?php
$col1 = new EJ\Grid\Column();
$col1->field("OrderID")->headerText("OrderID")->textAlign("right")->width(100);
$col2 = new EJ\Grid\Column();
$col2->field("CustomerID")->headerText("CustomerID")->width(70);
$col3 = new EJ\Grid\Column();
$col3->field("EmployeeID")->headerText("EmployeeID")->textAlign("right")->width(70);
$col4 = new EJ\Grid\Column();
$col4->field("ShipCountry")->headerText("ShipCountry")->width(70);
$col5 = new EJ\Grid\Column();
$col5->field("Freight")->headerText("Freight")->textAlign("right")->format("{0:C}")->width(70);
$gridColumns = array($col1,$col2,$col3,$col4,$col5);
$dataManager = new EJ\DataManager();
$dataManager->url('//mvc.syncfusion.com/Services/Northwnd.svc/Orders/')->offline(true);
$grid = new EJ\Grid("Grid");
echo $grid -> dataSource( $dataManager)->columns($gridColumns)->allowPaging(true)->render();
?>
</div>
<style>
.cols-sample-area {
margin:0 auto;
float:none;
}
</style> |
Hi Xavier,
Thank you for contacting Syncfusion support.
To overcome this problem, we suggest you to use ejDatamanager to bind the dataSource in Grid. Please refer to the below code example,
<?phprequire_once '../EJ/AutoLoad.php';?><div class="cols-sample-area"><?php$col1 = new EJ\Grid\Column();$col1->field("OrderID")->headerText("OrderID")->textAlign("right")->width(100);$col2 = new EJ\Grid\Column();$col2->field("CustomerID")->headerText("CustomerID")->width(70);$col3 = new EJ\Grid\Column();$col3->field("EmployeeID")->headerText("EmployeeID")->textAlign("right")->width(70);$col4 = new EJ\Grid\Column();$col4->field("ShipCountry")->headerText("ShipCountry")->width(70);$col5 = new EJ\Grid\Column();$col5->field("Freight")->headerText("Freight")->textAlign("right")->format("{0:C}")->width(70);$gridColumns = array($col1,$col2,$col3,$col4,$col5);$dataManager = new EJ\DataManager();$dataManager->url('//mvc.syncfusion.com/Services/Northwnd.svc/Orders/')->offline(true);$grid = new EJ\Grid("Grid");echo $grid -> dataSource( $dataManager)->columns($gridColumns)->allowPaging(true)->render();?></div><style>.cols-sample-area {margin:0 auto;float:none;}</style>
If you still facing the issue, please share the following information to serve you better1. Essential studio and browser version details.2. Please open the console window in browser and check whether any script error throws.3. An issue reproducing sample if possible or hosted link
Regards,
Jayaprakash K.
Index.php
<?php
require_once 'EJ/AutoLoad.php';
?>
<title>ejGrid with PHP</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel='nofollow' href="http://cdn.syncfusion.com/15.1.0.41/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" />
<div class="cols-sample-area">
<?php
$col1 = new EJ\Grid\Column();
$col1->field("help_category_id")->headerText("OrderID")->textAlign("right")->width(100);
$col2 = new EJ\Grid\Column();
$col2->field("name")->headerText("CustomerID")->width(70);
$col3 = new EJ\Grid\Column();
$col3->field("parent_category_id")->headerText("EmployeeID")->textAlign("right")->width(70);
$gridColumns = array($col1,$col2,$col3);
$dataManager = new EJ\DataManager();
$dataManager->url('http://localhost:8080/sample/data.php')->adaptor('UrlAdaptor');
$grid = new EJ\Grid("Grid");
echo $grid -> dataSource( $dataManager)->columns($gridColumns)->allowPaging(true)->render();
?>
</div>
<style>
.cols-sample-area {
margin:0 auto;
float:none;
}
</style>
data.php
<?php
//session_start();
//include("connection.php");
?>
<?php
/**
* Created by PhpStorm.
* User: christopheweibel
* Date: 16/01/15
* Time: 12:20
*/
header("Content-type:application/json");
$link = mysqli_connect('localhost', 'root', '', 'mysql');
$json_param = file_get_contents("php://input");
$params = json_decode($json_param,true);
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$skip = $params['skip'];
$take = $params['take'];
$query =$sql = "SELECT * FROM help_category";
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,$sql);
$count=mysqli_num_rows($countquery); //return total records count
$response=array("result"=>$json,"count"=>(int)$count);
echo json_encode($response);
?>
|
Hi Xavier,
Based on your request, we have created a sample using ejDataManager with UrlAdaptor and Mysql that can be downloaded from the following location.
Index.php
<?phprequire_once 'EJ/AutoLoad.php';?><title>ejGrid with PHP</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><link rel='nofollow' href="http://cdn.syncfusion.com/15.1.0.41/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" /><div class="cols-sample-area"><?php$col1 = new EJ\Grid\Column();$col1->field("help_category_id")->headerText("OrderID")->textAlign("right")->width(100);$col2 = new EJ\Grid\Column();$col2->field("name")->headerText("CustomerID")->width(70);$col3 = new EJ\Grid\Column();$col3->field("parent_category_id")->headerText("EmployeeID")->textAlign("right")->width(70);$gridColumns = array($col1,$col2,$col3);$dataManager = new EJ\DataManager();$dataManager->url('http://localhost:8080/sample/data.php')->adaptor('UrlAdaptor');$grid = new EJ\Grid("Grid");echo $grid -> dataSource( $dataManager)->columns($gridColumns)->allowPaging(true)->render();?></div><style>.cols-sample-area {margin:0 auto;float:none;}</style>
data.php
<?php//session_start();//include("connection.php");?><?php/*** Created by PhpStorm.* User: christopheweibel* Date: 16/01/15* Time: 12:20*/header("Content-type:application/json");$link = mysqli_connect('localhost', 'root', '', 'mysql');$json_param = file_get_contents("php://input");$params = json_decode($json_param,true);/* check connection */if (!$link) {printf("Connect failed: %s\n", mysqli_connect_error());exit();}$skip = $params['skip'];$take = $params['take'];$query =$sql = "SELECT * FROM help_category";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,$sql);$count=mysqli_num_rows($countquery); //return total records count$response=array("result"=>$json,"count"=>(int)$count);echo json_encode($response);?>
For curd operations, please refer to the below link.
Regards,
Jayaprakash K.