Reputation: 4029
This is really frustrating me. I feel like I'm doing everything right but my grid just won't display anything. I KNOW I'm sending back the data correctly, because I can see it in Fiddler, and it's the exact same format as one of my example which works.
Data from Fiddler looks like this (JSON, as expected, with the "d", but there's 200 objects in the array, here I only show one.)
{"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}
}]
}
Here's the code for my grid. This is about the 50th version I've tried.
$(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"]
});
}
Here's my page method, this works fine:
[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;
}
}
I'm not just looking for a code fix here. If you can explain what's going on with this, I would really appreciate it. I have spent many hours reading the documentation and I suspect this has something to do with my model and schema being wrong, but the docs about those fields just don't have enough detail.
One really weird thing is, when I run the Ajax call, neither callback function runs. You can see I have a callback for both error and success - neither of those runs. I can see the Ajax call being made and the data coming back. I would expect one or the other of those functions to run - I mean, it has to be either success or error, right?
Upvotes: 0
Views: 392
Reputation: 2385
The schema
definition is supposed to be a part of the dataSource
definition. i.e. the schema
config is supposed to be nested under the dataSource
config.
Upvotes: 1