简体   繁体   English

Kendo UI Grid内联编辑

[英]Kendo UI Grid inline edit

Hi I'm trying to do kendo grid and it doesn't work, shows the grid but no shows data. 嗨,我正在尝试做剑道网格,它不起作用,显示网格但没有显示数据。 I don't know what is wrong. 我不知道怎么了 I don't know how parametersMap works. 我不知道parametersMap是如何工作的。 Please help me. 请帮我。

Controller 控制者

public ActionResult GetGeo(int id) 
{
    var list = data.getGeoList(id);
    return Json(new {list}, JsonRequestBehavior.AllowGet);
}

public ActionResult UpdateGeo(int id)
{
    var success = data.UpdatetGeo(id);
    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

public ActionResult DeleteGeo(int id)
{
    var success = data.DeletetGeo(id);
    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

public ActionResult CreateGeo(GeoContent model)
{
    var success = data.CreateGeo(model);
    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

Here is script 这是脚本

<script>
$(document).ready(function () {

        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/Home/GetGeo/",
                    dataType: "json",
                    contentType: "application/json",
                    data: {id:5}

                },
                update: {
                    url:  "/Home/UpdateGeo",
                    dataType: "json",
                    contentType: "application/json"
                },
                destroy: {
                    url:  "/Home/DeleteGeo",
                    dataType: "json",
                    contentType: "application/json"
                },
                create: {
                    url:  "/Home/CreateGeo",
                    dataType: "json",
                    contentType: "application/json"
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            },
            batch: true,
            pageSize: 20,
            schema: {
                model: {
                    id: "GeoId",
                    fields: {
                        GeoId: { editable: false, nullable: true },
                        ContentId: { editable: false, nullable: true },
                        Latitude: { type: "number", validation: { required: true, min: 1 } },
                        Longitude: { type: "number", validation: { required: true, min: 1 } },

                    }
                }
            }
        });

    $("#grid4").kendoGrid({
        dataSource: dataSource,
        navigatable: true,
        pageable: true,
        height: 550,
        toolbar: ["create", "save", "cancel"],
        columns: [
            { field: "Latitude", title: "Latitude", width: 120 },
            { field: "Longitude", title: "Longitude", width: 120 },
            { command: "destroy", title: "&nbsp;", width: 150 }],
        editable: true
    });
});

Json data return: http://localhost:53232/Home/GetGeo?id=5 Json数据返回: http:// localhost:53232 / Home / GetGeo?id = 5

{"list": [
  {
    "GeoId":1,
    "ContentId":5,
    "Latitude":4.716168,
    "Longitude":-70.78373
  },{
    "GeoId":2,
    "ContentId":5,
    "Latitude":4.718171,
    "Longitude":-70.76253
  }
]}

Since your data is actually nested on list element, you need to add to your schema data: "list" . 由于您的数据实际上是嵌套在list元素上的,因此您需要添加到架构data: "list" It should look something like: 它看起来应该像这样:

schema: {
    data:"list",
    model: {
        id: "GeoId",
        fields: {
            GeoId: { editable: false, nullable: true },
            ContentId: { editable: false, nullable: true },
            Latitude: { type: "number", validation: { required: true, min: 1 } },
            Longitude: { type: "number", validation: { required: true, min: 1 } }

        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM