I followed all the steps, but my grid remains empty. Any help greatly appreciated.
<?php
$transport = new \Kendo\Data\DataSourceTransport();
$read = new \Kendo\Data\DataSourceTransportRead();
// Specify the url of the PHP page which will act as the remote service
$read->url('14streamPDO.php')
->type('POST');
$transport->read($read);
// Configure the model
$model = new \Kendo\Data\DataSourceSchemaModel();
$idField = new \Kendo\Data\DataSourceSchemaModelField('id');
$idField->type('number');
$apynoField = new \Kendo\Data\DataSourceSchemaModelField('apyno');
$apynoField->type('string');
$edadField = new \Kendo\Data\DataSourceSchemaModelField('edad');
$edadField->type('number');
$model->addField($idField)
->addField($apynoField)
->addField($edadField);
$schema = new \Kendo\Data\DataSourceSchema();
$schema->model($model);
$dataSource = new \Kendo\Data\DataSource();
// Configure data source
$dataSource->transport($transport)
->schema($schema);
?>
<!-- Create a kendo grid, configure its columns and set its data source.
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<?php
$grid = new \Kendo\UI\Grid('grid');
$idColumn = new \Kendo\UI\GridColumn();
$idColumn->field('id');
$apynoColumn = new \Kendo\UI\GridColumn();
$apynoColumn->field('apyno');
$edadColumn = new \Kendo\UI\GridColumn();
$edadColumn->field('edad');
// Configure columns, enable paging, filtering, sorting and grouping
$grid->addColumn($idColumn, $apynoColumn, $edadColumn)
->sortable(true);
?>
<!-- Output the widget echoing the render method
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<?php
echo $grid->render();
?>
Code for the connection:
<?php
// set up for using PDO
$user = 'root';
$pass = 'root';
$host = 'localhost';
$db_name = 'garchazon';
// set up DSN
$dsn = "mysql:host=$host;dbname=$db_name";
$db = new PDO($dsn, $user, $pass);
$query = "SELECT id, apyno, edad FROM Employee";
$stmt = $db->prepare($query);
$stmt->execute();
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Set response content type
header('Content-Type: application/json');
// Return JSON
echo json_encode($products);
?>
and my json output:
[{"id":"1","apyno":"Rosa Melroso","edad":"18","deporte":"Running"},{"id":"2","apyno":"Debora Melo","edad":"22","deporte":"Gym"},{"id":"3","apyno":"Debora Teste","edad":"23","deporte":"Mountain Bike"},{"id":"4","apyno":"Debora Dora de Cabezas","edad":"66","deporte":"Gym"},{"id":"5","apyno":"Rita Lazo","edad":"33","deporte":"Running"},{"id":"6","apyno":"Aquiles Bailoyo","edad":"28","deporte":"Running"},{"id":"7","apyno":"Omar Icon","edad":"21","deporte":"Running"},{"id":"8","apyno":"Paty Tasalhombro","edad":"27","deporte":"Mountain Bike"},{"id":"9","apyno":"Elber Galarga","edad":"34","deporte":"Gym"},{"id":"10","apyno":"Analisa Melchoto","edad":"55","deporte":"Gym"},{"id":"11","apyno":"Ester Mosobicho","edad":"44","deporte":"Mountain Bike"},{"id":"12","apyno":"Cindy Entes","edad":"36","deporte":"Running"},{"id":"13","apyno":"Lucila Tanga","edad":"32","deporte":"Running"},{"id":"14","apyno":"Marcelo Metio","edad":"53","deporte":"Mountain Bike"},{"id":"15","apyno":"Andy Arrea","edad":"29","deporte":"Running"},{"id":"16","apyno":"Jean Pier Napeluda","edad":"38","deporte":"Mountain Bike"},{"id":"17","apyno":"Jesica Galindo","edad":"21","deporte":"Running"},{"id":"18","apyno":"Monica Galindo","edad":"21","deporte":"Gym"},{"id":"19","apyno":"Rebeca Galindo","edad":"21","deporte":"Running"},{"id":"20","apyno":"Rosa Mile\u00f1o Ardiente","edad":"64","deporte":"Gym"},{"id":"21","apyno":"Elvio Lador","edad":"33","deporte":"Gym"},{"id":"22","apyno":"Debora Dora Dejapis","edad":"34","deporte":"Mountain Bike"},{"id":"23","apyno":"Aquiles Baeza Parada","edad":"23","deporte":"Gym"}]