如何为php使用KendoUIGrid?
我在php中使用剑道UI作为web应用程序;我正在尝试创建和使用网格 代码是:如何为php使用KendoUIGrid?,php,mysql,database,kendo-ui,kendo-grid,Php,Mysql,Database,Kendo Ui,Kendo Grid,我在php中使用剑道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: applicat
<?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(' ')
->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();
}
?>
有了它,我只能得到数据,不能删除、编辑和创建
我必须通过自定义选择来获取数据(我不想显示已删除的项目),并且只显示实验室名称
当我更新、编辑或创建时,我还需要设置网格中未显示的其他字段。
我该怎么做
谢谢使用隐藏列,然后您可以在创建和编辑中使用then。@R.K.Saini ok,我如何使用手动传递数据的字段创建和编辑?您是指如何在服务器端管理创建和编辑请求?为此,您可以更改create和edit的switch语句,$request对象保存从浏览器发送到服务器的数据,在这里您可以添加手动输入,如created_by、edited_by和其他内容