Grid PHP Class Overview
The Kendo UI Grid for PHP is a server-side wrapper for the Kendo UI Grid widget.
Getting Started
The Basics
There are two ways to bind a Kendo UI Grid for PHP:
- Locally—Local binding binds the Grid to a PHP array.
- Remotely—During remote binding the Grid makes AJAX requests and is bound to the JSON result.
Configuration
Below are listed the steps for you to follow when configuring the Kendo UI Grid for local binding.
Step 1 Make sure you followed all the steps from the introductory article on Telerik UI for PHP—include the autoloader, JavaScript, and CSS files.
Step 2 Create an array to which the Grid will be bound.
<?php
$data = array(
array('name' => 'John Doe', 'age' => 32),
array('name' => 'Jane Doe', 'age' => 29)
);
?>
Step 3 Create a DataSource
and set its data
.
<?php
$dataSource = new \Kendo\Data\DataSource();
$dataSource->data($data);
?>
Step 4 Create a Grid, configure its columns and set its dataSource
.
<?php
$nameColumn = new \Kendo\UI\GridColumn();
$nameColumn->field('name');
$ageColumn = new \Kendo\UI\GridColumn();
$ageColumn->field('age');
$grid = new \Kendo\UI\Grid('grid');
$grid->addColumn($nameColumn, $ageColumn)
->dataSource($dataSource);
?>
Step 5 Output the Grid by echoing the result of the render
method.
<?php
echo $grid->render();
?>
Event Handling
You can subscribe to all Grid events.
Specify Function Names
The example below demonstrates how to subscribe for events by specifying a JavaScript function name.
<?php
$grid = new \Kendo\UI\Grid('grid');
// The 'grid_dataBound' JavaScript function will handle the 'dataBound' event of the grid
$grid->dataBound('grid_dataBound');
echo $grid->render();
?>
<script>
function grid_dataBound() {
// Handle the dataBound event
}
</script>
Provide Inline Code
The example below demonstrates how to provide inline JavaScript code.
<?php
$grid = new \Kendo\UI\Grid('grid');
// Provide inline JavaScript code that will handle the 'dataBound' event of the grid
$grid->dataBound('function() { /* Handle the dataBound event */ }');
echo $grid->render();
?>
Reference
Client-Side Instances
You can reference the client-side Kendo UI Grid instance via jQuery.data()
. Once a reference is established, use the Grid API to control its behavior.
<?php
$grid = new \Kendo\UI\Grid('productGrid');
echo $grid->render();
?>
<script>
$(function() {
// The constructor parameter is used as the 'id' HTML attribute of the grid
var grid = $("#productGrid").data("kendoGrid")
});
</script>