Kendo Grid只是拒绝显示我的数据

时间:2013-08-29 16:01:43

标签: json kendo-ui kendo-grid

这真让我很沮丧。我觉得我正在做的一切正确,但我的网格不会显示任何东西。我知道我正在正确地发回数据,因为我可以在Fiddler中看到它,并且它与我的一个有效的格式完全相同。

来自Fiddler的数据看起来像这样(JSON,正如预期的那样,带有“d”,但数组中有200个对象,这里我只显示一个。)

{"d":
    [{"__type":"DisputeProjectManagerModel.DISP_PROJECT_NAME_MASTER",
     "PROJECT_ID_NUMBER":241,
     "PROJECT_NAME":"AT\u0026T Settlement - Stake date payment",
     "CATEGORY":null,
     "CONTRIBUTION":"N",
     "WIN_RATE":"N",
     "SETTLEMENT":"N",
     "DESCRIPTION":null,
     "JUSTIFICATION":null,
     "ACTIVE":"N",
     "MODIFIED_USER":"SYSTEM",
     "MODIFIED_DATE":"\/Date(1377744633000)\/",
     "EntityState":2,
     "EntityKey":{"EntitySetName":"DISP_PROJECT_NAME_MASTER","EntityContainerName":"DisputeProjectManagerEntities","EntityKeyValues":[{"Key":"PROJECT_ID_NUMBER","Value":241}],
     "IsTemporary":false}
    }]
} 

这是我网格的代码。这是我尝试过的第50个版本。

$(document).ready(function () {
    setupGrid();
});

function setupGrid() {
    alert("click OK to make Ajax call");

    $("#projectManagerGrid").kendoGrid({
        columns: ["PROJECT_ID_NUMBER", "PROJECT_NAME", "CATEGORY", "CONTRIBUTION", "WIN_RATE", "SETTLEMENT", "DESCRIPTION", "JUSTIFICATION", "ACTIVE", "MODIFIED_USER", "MODIFIED_DATE"],
        dataSource: {
        type: "odata",
            transport: {
                read: {
                    type: "POST",
                    url: "/special_pages/DisputeProjectManager.aspx/getProjects",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) { alert('WORKED!'); },
                    error: function (xhr, textStatus, errorThrown) { handleAjaxError(xhr, textStatus, errorThrown); }
                },
                parameterMap: function (data, type) {
                    return kendo.stringify(data);
                }
            }
        },
        schema: {
            data: "d",
            columns: ["PROJECT_ID_NUMBER", "PROJECT_NAME", "CATEGORY", "CONTRIBUTION", "WIN_RATE", "SETTLEMENT", "DESCRIPTION", "JUSTIFICATION", "ACTIVE", "MODIFIED_USER", "MODIFIED_DATE"],
            model: {
                id: "PROJECT_ID_NUMBER",
                fields: {
                    "PROJECT_ID_NUMBER": { type: "number", editable: false },
                    "PROJECT_NAME": { type: "string", editable: true },
                    "CATEGORY": { type: "string", editable: true },
                    "CONTRIBUTION": { type: "string", editable: true },
                    "WIN_RATE": { type: "string", editable: true },
                    "SETTLEMENT": { type: "string", editable: true },
                    "DESCRIPTION": { type: "string", editable: true },
                    "JUSTIFICATION": { type: "string", editable: true },
                    "ACTIVE": { type: "string", editable: true },
                    "MODIFIED_USER": { type: "string", editable: false },
                    "MODIFIED_DATE": { type: "date", editable: false }
                }
            }
        },
        editable: {
            update: true,
            create: true,
            destroy: false
        },
        toolbar: ["create", "save", "cancel"]
    });
}

这是我的页面方法,这很好用:

[WebMethod]
public static List<DISP_PROJECT_NAME_MASTER> getProjects() {
    try {
        using (DisputeProjectManagerEntities ctx = new DisputeProjectManagerEntities()) {
            var q = (from e in ctx.DISP_PROJECT_NAME_MASTER orderby e.MODIFIED_DATE descending select e);
            return q.ToList<DISP_PROJECT_NAME_MASTER>();
        }
    } catch {
        return null;
    }
}

我不只是在寻找代码修复程序。如果你能解释一下这是怎么回事,我真的很感激。我花了很多时间阅读文档,我怀疑这与我的模型和架​​构有关,但是关于这些字段的文档没有足够的细节。

一个非常奇怪的事情是,当我运行Ajax调用时,两个回调函数都没有运行。您可以看到我有错误和成功的回调 - 这些都不是。我可以看到正在进行的Ajax调用以及返回的数据。我希望这些函数中的一个或另一个能运行 - 我的意思是,它必须是成功还是错误,对吧?

1 个答案:

答案 0 :(得分:1)

schema定义应该是dataSource定义的一部分。即schema配置应该嵌套在dataSource配置下。