This question is locked. New answers and comments are not allowed.
Hello Guys,
I am trying to get the "Grid Batch Editing" PHP code http://demos.kendoui.com/web/grid/editing.html to render but I am unable to do so. I am using a MySQL database and the connection is working fine. There is data in the database but I am not able to get any data to display with Kendo. I have made a simple table with just one field I want to display as I am learning to use Kendo. See my code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link href="../../kendouiphp/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="../../kendouiphp/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
<script src="../../kendouiphp/js/jquery.min.js"></script>
<script src="../../kendouiphp/js/kendo.all.min.js"></script>
</head>
<body>
<form class="form" action="doctorsKendoUiCrud.php" method="post" id="DoctorCrudGridForm" onsubmit="">
<?php
// Kendo UI CRUD Grid for doctors
// follow:
// http://demos.kendoui.com/web/grid/editing.html
// http://www.kendoui.com/forums/php/grid/php-wrappers---pdo.aspx
require_once '../../kendouiphp/wrappers/php/lib/DataSourceResult.php';
require_once '../../kendouiphp/wrappers/php/lib/Kendo/Autoload.php';
require_once("../../admin/lib/pdo.sql.php");
require_once("../../admin/AdminObject.php");
//$result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*******');
$admin_object = new AdminObject();
//$admin_object->die_array($_GET);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//if ($_SERVER['REQUEST_METHOD'] == 'GET') {
//die("We are here");
header('Content-Type: application/json');
$request = json_decode(file_get_contents('php://input'));
//$result = new DataSourceResult('sqlite:../../sample.db');
$result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*********');
$type = $_GET['type'];
$columns = array('doctor_id', 'doctor_firstname');
switch($type) {
case 'create':
$result = $result->create('doctors', $columns, /*$request->models,*/ 'doctor_id');
break;
case 'read':
//$result = $result->read('doctors', $columns, $request);
$result = $result->read('doctors', $columns);
break;
case 'update':
$result = $result->update('doctors', $columns, /*$request->models,*/ 'doctor_id');
break;
case 'destroy':
$result = $result->destroy('doctors', /*$request->models,*/ 'doctor_id');
break;
}
echo json_encode($result);
exit;
}
$transport = new \Kendo\Data\DataSourceTransport();
$create = new \Kendo\Data\DataSourceTransportCreate();
$create->url('doctorsKendoUiCrud.php?type=create')
->contentType('application/json')
->type('POST');
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url('doctorsKendoUiCrud.php?type=read')
->contentType('application/json')
->type('POST');
$update = new \Kendo\Data\DataSourceTransportUpdate();
$update->url('doctorsKendoUiCrud.php?type=update')
->contentType('application/json')
->type('POST');
$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy->url('doctorsKendoUiCrud.php?type=destroy')
->contentType('application/json')
->type('POST');
$transport->create($create)
->read($read)
->update($update)
->destroy($destroy)
->parameterMap('function(data) {
return kendo.stringify(data);
}');
$model = new \Kendo\Data\DataSourceSchemaModel();
$doctorIDField = new \Kendo\Data\DataSourceSchemaModelField('doctor_id');
$doctorIDField->type('number')
->editable(false)
//->nullable(true);
->nullable(false);
$doctorNameField = new \Kendo\Data\DataSourceSchemaModelField('doctor_firstname');
$doctorNameField->type('string')
->validation(array('required' => true));
$model->id('doctor_id')
->addField($doctorIDField)
->addField($doctorNameField);
$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
//->data('doctor_firstnamexx')
->errors('errors')
->model($model)
->total('doctors');
//echo "This is the schema <br />\n<br />\n<br />\n";var_export($schema);die();
$dataSource = new \Kendo\Data\DataSource();
$dataSource->transport($transport)
->batch(true)
->pageSize(30)
->schema($schema);
$grid = new \Kendo\UI\Grid('grid');
$doctorName = new \Kendo\UI\GridColumn();
$doctorName->field('doctor_firstname')
->title('Doctor Name');
$command = new \Kendo\UI\GridColumn();
$command->addCommandItem('destroy')
->title(' ')
->width(110);
//echo "This is the Doctors Grid PreSet <br />\n<br />\n<br />\n";var_export($grid);die();
$grid->addColumn($doctorName)
->dataSource($dataSource)
->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'),
new \Kendo\UI\GridToolbarItem('save'), new \Kendo\UI\GridToolbarItem('cancel'))
->height(400)
->navigatable(true)
->editable(true)
->pageable(true);
//echo "This is the Doctors Grid PostSet <br />\n<br />\n<br />\n";var_export($grid);die();
echo $grid->render();
?>
</form>
</body>
</html>
Please let me know what I am doing wrong.
I am trying to get the "Grid Batch Editing" PHP code http://demos.kendoui.com/web/grid/editing.html to render but I am unable to do so. I am using a MySQL database and the connection is working fine. There is data in the database but I am not able to get any data to display with Kendo. I have made a simple table with just one field I want to display as I am learning to use Kendo. See my code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link href="../../kendouiphp/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="../../kendouiphp/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
<script src="../../kendouiphp/js/jquery.min.js"></script>
<script src="../../kendouiphp/js/kendo.all.min.js"></script>
</head>
<body>
<form class="form" action="doctorsKendoUiCrud.php" method="post" id="DoctorCrudGridForm" onsubmit="">
<?php
// Kendo UI CRUD Grid for doctors
// follow:
// http://demos.kendoui.com/web/grid/editing.html
// http://www.kendoui.com/forums/php/grid/php-wrappers---pdo.aspx
require_once '../../kendouiphp/wrappers/php/lib/DataSourceResult.php';
require_once '../../kendouiphp/wrappers/php/lib/Kendo/Autoload.php';
require_once("../../admin/lib/pdo.sql.php");
require_once("../../admin/AdminObject.php");
//$result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*******');
$admin_object = new AdminObject();
//$admin_object->die_array($_GET);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//if ($_SERVER['REQUEST_METHOD'] == 'GET') {
//die("We are here");
header('Content-Type: application/json');
$request = json_decode(file_get_contents('php://input'));
//$result = new DataSourceResult('sqlite:../../sample.db');
$result = new DataSourceResult('mysql:host=localhost;dbname=findatopdoc_v6Querytest;charset=utf8', 'root', '*********');
$type = $_GET['type'];
$columns = array('doctor_id', 'doctor_firstname');
switch($type) {
case 'create':
$result = $result->create('doctors', $columns, /*$request->models,*/ 'doctor_id');
break;
case 'read':
//$result = $result->read('doctors', $columns, $request);
$result = $result->read('doctors', $columns);
break;
case 'update':
$result = $result->update('doctors', $columns, /*$request->models,*/ 'doctor_id');
break;
case 'destroy':
$result = $result->destroy('doctors', /*$request->models,*/ 'doctor_id');
break;
}
echo json_encode($result);
exit;
}
$transport = new \Kendo\Data\DataSourceTransport();
$create = new \Kendo\Data\DataSourceTransportCreate();
$create->url('doctorsKendoUiCrud.php?type=create')
->contentType('application/json')
->type('POST');
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url('doctorsKendoUiCrud.php?type=read')
->contentType('application/json')
->type('POST');
$update = new \Kendo\Data\DataSourceTransportUpdate();
$update->url('doctorsKendoUiCrud.php?type=update')
->contentType('application/json')
->type('POST');
$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy->url('doctorsKendoUiCrud.php?type=destroy')
->contentType('application/json')
->type('POST');
$transport->create($create)
->read($read)
->update($update)
->destroy($destroy)
->parameterMap('function(data) {
return kendo.stringify(data);
}');
$model = new \Kendo\Data\DataSourceSchemaModel();
$doctorIDField = new \Kendo\Data\DataSourceSchemaModelField('doctor_id');
$doctorIDField->type('number')
->editable(false)
//->nullable(true);
->nullable(false);
$doctorNameField = new \Kendo\Data\DataSourceSchemaModelField('doctor_firstname');
$doctorNameField->type('string')
->validation(array('required' => true));
$model->id('doctor_id')
->addField($doctorIDField)
->addField($doctorNameField);
$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
//->data('doctor_firstnamexx')
->errors('errors')
->model($model)
->total('doctors');
//echo "This is the schema <br />\n<br />\n<br />\n";var_export($schema);die();
$dataSource = new \Kendo\Data\DataSource();
$dataSource->transport($transport)
->batch(true)
->pageSize(30)
->schema($schema);
$grid = new \Kendo\UI\Grid('grid');
$doctorName = new \Kendo\UI\GridColumn();
$doctorName->field('doctor_firstname')
->title('Doctor Name');
$command = new \Kendo\UI\GridColumn();
$command->addCommandItem('destroy')
->title(' ')
->width(110);
//echo "This is the Doctors Grid PreSet <br />\n<br />\n<br />\n";var_export($grid);die();
$grid->addColumn($doctorName)
->dataSource($dataSource)
->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'),
new \Kendo\UI\GridToolbarItem('save'), new \Kendo\UI\GridToolbarItem('cancel'))
->height(400)
->navigatable(true)
->editable(true)
->pageable(true);
//echo "This is the Doctors Grid PostSet <br />\n<br />\n<br />\n";var_export($grid);die();
echo $grid->render();
?>
</form>
</body>
</html>
Please let me know what I am doing wrong.