Php Kendo UI带数据源(CRUD)

时间:2014-08-28 07:53:15

标签: javascript php kendo-ui crud

我正在努力使用Kendo UI获得CRUD的功能?我的创建和更新选项似乎不起作用,但我的阅读,任何帮助?我已经通过大量的教程,但只是不能让它工作。谢谢你。

这是我的代码,这是我的Index.php文件:

<!DOCTYPE html>
<html>
<head>

<link href="styles/kendo.common.min.css" rel="stylesheet" />
<link href="styles/kendo.default.min.css" rel="stylesheet" />
<link href="styles/kendo.dataviz.min.css" rel="stylesheet" />
<link href="styles/kendo.dataviz.default.min.css" rel="stylesheet" />

<script src="js/jquery.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/kendo.all.min.js"></script>
</head>
<body>

<div id="example">
<div id="grid"></div>
<script>

    $(document).ready(function () {
            dataSource = new kendo.data.DataSource({
                batch: true,
                transport: {

                    read: "data/ussd.php"
                },

                update: {
                    url: "data/ussd.php",
                    type: "POST"
                },
                create: {

                    url: "data/create.php",
                    type: "PUT"
                },
                parameterMap: function(options, operation){
                    if(operation !== "read" && option.models){
                        return{models : kendo.string(options.models)}
                    }
                },

                pageSize: 20,
                schema: {
                    data: "data",
                    model: {
                        id: "id",
                        fields: {
                             id: {editable: false, nullable: true},
                             msisdn: {editable: true, type: "number"},
                             company: {editable: true},
                             description: {editable: true},
                             ussd: {editable: true},
                             updated: {editable: true, type: "date"},
                             added: {editable: true, type: "date"}
                        }
                    }
                },

                serverFiltering: true,
                serverSorting: true

            });

        $("#grid").kendoGrid({
            dataSource:  dataSource,
            pageable: true,
            filterable: true,
            sortable: true,

            height: 500,
            toolbar: ["create", "save", "cancel"],
            columns: [

                { field: "id", title: "ID", width: "45px" },
                { field: "msisdn", title: "MSISDN", width: "75px" },
                { field: "company", title: "Company", width: "100px" },
                { field: "description", title:"Description", width: "100px" },
                { field: "ussd", title: "USSD", width: "100px" },
                { field: "updated", title: "Updated", width: "100px" },
                { field: "added", title: "Added", width: "100px" },
                { command: ["edit", "destroy"], title: "&nbsp;", width: "140px" }],

            schema: {
                model: { id: "id" }
            },

            editable: "inline",
            navigable: true
        });


    });



</script>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

这是我改变的,基本上URL和类型不正确,没有遵循正确的路径

$(document).ready(function () {

        dataSource = new kendo.data.DataSource({

            transport: {

                read: "data/whitelist.php?type=read",
                update: {url:"data/whitelist.php?type=update", type:"POST"},
                create: {url:"data/whitelist.php?=create",type:"POST"},
                destroy: {url:"data/whitelist.php?type=destroy",type:"POST"}
            },


            batch: false,
            pageSize: 20,
            schema: {

                model: {
                    id: "id",
                    fields: {
                        id: {editable: false, nullable: true},
                        msisdn: {editable: true, type: "number"},
                        company: {editable: true},
                        description: {editable: true},
                        ussd: {editable: true},
                        updated: {editable: true, type: "date"},
                        added: {editable: true, type: "date"}
                    }
                }
            },

            serverFiltering: true,
            serverSorting: true

        });

        $("#grid").kendoGrid({
            dataSource:  dataSource,
            pageable: true,
            filterable: true,
            sortable: true,

            height: 430,
            toolbar: [{name: "create", text: "Add New"}, "save", "cancel"],
            columns: [

                { field: "id", title: "ID", width: "26px" },
                { field: "msisdn", title: "MSISDN", width: "50px" },
                { field: "company", title: "Company", width: "65px" },
                { field: "description", title:"Description", width: "65px" },
                { field: "ussd", title: "USSD", width: "50px" },
                { field: "updated", title: "Updated", width: "70px" },
                { field: "added", title: "Added", width: "70px" },
                { command: [{text:"Edit", name:"edit"}, {text:"Delete",name:"destroy"}], title: " ", width: "80px" }],

            editable: "inline",
            navigable: true


        });
    });

答案 1 :(得分:0)

{                    read: "data/ussd.php"
                },

                update: {
                    url: "data/ussd.php",
                    type: "POST"
                },
                create: {

                    url: "data/create.php",
                    type: "PUT"
                }

您的阅读和更新都使用相同的php文件。

什么是创建中的PUT类型?

只需将更新URL更改为其他php文件,并获取发布的值以在数据库中运行查询。 并将创建的类型也改为POST,因为你也在为其他人使用POST ..

在“更新”部分下,更改此

url: "data/ussd.php",

进入

url: "data/update.php",

并尝试按照之前的说法获取发布的值。看看是否适合你。