如何使用Kendo UI Grid for php?

时间:2017-04-03 10:06:01

标签: php mysql database kendo-ui kendo-grid

我在WEB中使用Kendo UI作为Web应用程序;我正在尝试创建和使用网格。

代码是:

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

require ("config_inc.php");
require_once ("../ui/lib/DataSourceResult.php");
require_once ("../ui/lib/Kendo/Autoload.php");

header('Content-Type: application/json');

$request = json_decode(file_get_contents('php://input'));
$result = new DataSourceResult('mysql:host=localhost;dbname=xxx;charset=utf8', 'xxx', 'xxx');
$type = $_GET['type'];

$columns = array('id', 'lab_name', 'created_on', 'created_by', 'edited_on', 'edited_by', 'deleted_on', 'deleted_by');

switch($type) {
    case 'create':
        $result = $result->create('laboratory', $columns, $request->models, 'id');
        break;
    case 'read':
        $result = $result->read('laboratory', $columns, $request);
        break;
    case 'update':
        $result = $result->update('laboratory', $columns, $request->models, 'id');
        break;
    case 'destroy':
        $result = $result->destroy('laboratory', $request->models, 'id');
        break;
}

echo json_encode($result, JSON_NUMERIC_CHECK);
exit;
}

function diaplayLaboratory() {

require_once ("inc/config_inc.php");
require_once ("ui/lib/DataSourceResult.php");
require_once ("ui/lib/Kendo/Autoload.php");

$read = new \Kendo\Data\DataSourceTransportRead();
$read ->url('inc/laboratory.php?type=read')
      ->contentType('application/json')
      ->type('POST');

$create = new \Kendo\Data\DataSourceTransportCreate();
$create ->url('inc/laboratory.php?type=create')
        ->contentType('application/json')
        ->type('POST');

$update = new \Kendo\Data\DataSourceTransportUpdate();
$update ->url('inc/laboratory.php?type=update')
        ->contentType('application/json')
        ->type('POST');

$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy ->url("inc/laboratory.php?type=destroy")
         ->contentType('application/json')
         ->type('POST');

$transport = new \Kendo\Data\DataSourceTransport();
$transport ->create($create)
           ->read($read)
           ->update($update)
           ->destroy($destroy)
           ->parameterMap('function(data) {
                return kendo.stringify(data);
            }');

$labNameValidation = new \Kendo\Data\DataSourceSchemaModelFieldValidation();
$labNameValidation ->required(true)
                   ->min(1);

$labName = new \Kendo\Data\DataSourceSchemaModelField('lab_name');
$labName ->type('string')
         ->validation($labNameValidation);

$model = new \Kendo\Data\DataSourceSchemaModel();
$model ->id('id')
       ->addField($labName);

$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
       ->errors('errors')
       ->model($model);

$dataSource = new \Kendo\Data\DataSource();
$dataSource ->transport($transport)
            ->pageSize(20)
            ->schema($schema);

$laboratoryName = new \Kendo\UI\GridColumn();
$laboratoryName ->field('lab_name')
                ->title(T_("lab_name"));

$command = new \Kendo\UI\GridColumn();
$command ->addCommandItem("edit")
         ->addCommandItem("delete")
         ->title('&nbsp;')
         ->width(250);

$grid = new \Kendo\UI\Grid('grid');
$grid ->addColumn($laboratoryName, $command)
      ->dataSource($dataSource)
      ->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'))
      ->editable('inline')
      ->scrollable(false);

echo $grid ->render();

}

?>

有了这个我只得到数据,我无法删除,编辑和创建。

我必须使用自定义选择获取数据(我不想显示已删除的项目)并仅显示lab_name。

当我更新,编辑或创建时,我还需要设置我未在网格中显示的其他字段。 我怎么能这样做?

由于

0 个答案:

没有答案