This is a migrated thread and some comments may be shown as answers.

PHP back end, HTML5/JavaScript front end and MySQL

1 Answer 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 07 May 2015, 04:57 PM

Please tell me what I'm doing wrong?

PHP back end editing.php

01.<?php
02.require_once 'lib/DataSourceResult.php';
03.require_once 'lib/Kendo/Autoload.php';
04. 
05.if ($_SERVER['REQUEST_METHOD'] == 'POST') {
06.    header('Content-Type: application/json');
07. 
08.    $request = json_decode(file_get_contents('php://input'));
09. 
10.    $result = new DataSourceResult('mysql:host=localhost;dbname=mydb;charset=utf8', 'root', '********');
11. 
12.    $type = $_GET['type'];
13. 
14.    $columns = array('project_id', 'code_tk', 'title', 'small_title');
15. 
16.    switch($type) {
17.        case 'create':
18.            $result = $result->create('projects', $columns, $request->models, 'project_id');
19.            break;
20.        case 'read':
21.            $result = $result->read('projects', $columns, $request);
22.            break;
23.        case 'update':
24.            $result = $result->update('projects', $columns, $request->models, 'project_id');
25.            break;
26.        case 'destroy':
27.            $result = $result->destroy('projects', $request->models, 'project_id');
28.            break;
29.    }
30. 
31.    echo json_encode($result,JSON_NUMERIC_CHECK);
32. 
33.    exit;
34.}
35.?>

HTML5/JavaScript front end index.html

01.<!DOCTYPE html>
02.<html>
03.<head>
04.    <!--<base href="http://demos.telerik.com/kendo-ui/grid/editing">-->
05.    <style>html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }</style>
06.    <title></title>
07.    <link rel="stylesheet" href="css/kendo.common-office365.min.css" />
08.    <link rel="stylesheet" href="css/kendo.office365.min.css" />
09.    <!--<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.min.css" />-->
10.    <!--<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.office365.min.css" />-->
11. 
12.    <script src="js/jquery.min.js"></script>
13.    <script src="js/kendo.all.min.js"></script>
14.</head>
15.<body>
16.<div id="example">
17.    <div id="grid"></div>
18. 
19.    <script>
20.        $(document).ready(function () {
21.            var crudServiceBaseUrl = "editing.php",
22.                    dataSource = new kendo.data.DataSource({
23.                        transport: {
24.                            read:  {
25.                                url: crudServiceBaseUrl + "?type=read",
26.                                contentType: "application/json; charset=utf-8",
27.                                type: "POST",
28.                                dataType: "json"
29.                            },
30.                            update: {
31.                                url: crudServiceBaseUrl + "?type=update",
32.                                contentType: "application/json; charset=utf-8",
33.                                type: "POST",
34.                                dataType: "json"
35.                            },
36.                            destroy: {
37.                                url: crudServiceBaseUrl + "?type=destroy",
38.                                contentType: "application/json; charset=utf-8",
39.                                type: "POST",
40.                                dataType: "json"
41.                            },
42.                            create: {
43.                                url: crudServiceBaseUrl + "?type=create",
44.                                contentType: "application/json; charset=utf-8",
45.                                type: "POST",
46.                                dataType: "json"
47.                            },
48.                            parameterMap: function(options, operation) {
49.                                if (operation !== "read" && options.models) {
50.                                    return {models: kendo.stringify(options.models)};
51.                                }
52.                            }
53.                        },
54.                        batch: true,
55.                        pageSize: 20,
56.                        schema: {
57.                            model: {
58.                                id: "project_id",
59.                                fields: {
60.                                    project_id: { editable: false, nullable: false },
61.                                    code_tk: { type: "number", validation: { min: 0, required: true } },
62.                                    title: { type: "string" },
63.                                    small_title: { type: "string" }
64.                                }
65.                            }
66.                        }
67.                    });
68. 
69.            $("#grid").kendoGrid({
70.                dataSource: dataSource,
71.                navigatable: true,
72.                pageable: true,
73.                height: 550,
74.                toolbar: ["create", "save", "cancel"],
75.                columns: [
76.                    "code_tk",
77.                    { field: "title", title: "title", width: 120 },
78.                    { field: "small_title", title: "small_title", width: 120 },
79.//                    { field: "Discontinued", width: 120 },
80.                    { command: "destroy", title: " ", width: 150 }],
81.                editable: true
82.            });
83.        });
84.    </script>
85.</div>
86. 
87. 
88.</body>
89.</html>

1 Answer, 1 is accepted

Sort by
0
Ser
Top achievements
Rank 1
answered on 09 May 2015, 10:34 PM

I found a solution to the problem

 

parameterMap: function(data) {
    return kendo.stringify(data);
}

and

schema: {
    data: "data",
    total: "total",
    model: {
        id: "project_id",
        fields: {
            project_id: { editable: false, nullable: true },
            code_tk: { type: "number" },
            title: { type: "string" },
            small_title: { type: "string" }
        }
    }
}

Tags
Grid
Asked by
Sergey
Top achievements
Rank 1
Answers by
Ser
Top achievements
Rank 1
Share this question
or