Syncfusion TreeGrid 和带有 WebAPI 的网格在删除时不起作用
Syncfusion TreeGrid and Grid with WebAPI doesn't work on delete
我已经设置了一个 treeGrid(网格是相同的)以使用他们的 DataManager 通过 ASP.NET WebAPI 获取数据:
var categoryID=15;
var dataManager = ej.DataManager({
url: "/API/myrecords?categoryID=" + categoryID,
adaptor: new ej.WebApiAdaptor()
});
$("#treeGridContainer").ejTreeGrid({
dataSource: dataManager,
childMapping: "Children",
treeColumnIndex: 1,
isResponsive: true,
contextMenuSettings: {
showContextMenu: true,
contextMenuItems: ["add", "edit", "delete"]
},
contextMenuOpen: contextMenuOpen,
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal', editMode: "rowEditing" },
columns: [
{ field: "RecordID", headerText: "ID", allowEditing: false, width: 20, isPrimaryKey: true },
{ field: "RecordName", headerText: "Name", editType: "stringedit" },
],
actionBegin: function (args) {
console.log('ActionBegin: ', args);
if (args.requestType === "add") {
//add new record, managed manually...
var parentID = 0;
if (args.level != 0) {
parentID = args.parentItem.TaxonomyID;
}
args.data.TaxonomyID = 0;
addNewRecord(domainID, parentID, args.data, args.model.selectedRowIndex);
}
}
});
GET 工作完美。
PUT 工作正常,因为我手动管理它,因为它根本不是从 DataManager 调用的,无论如何我想管理 TreeGrid 中记录的更新。
问题出在 DELETE 上,当我从 TreeGrid 中某个项目的上下文菜单中单击“删除”时,DataManager 会调用它。
它调用以下 URL:
http://localhost:50604/API/myrecords?categoryID=15/undefined
显然,我得到一个 405(方法不允许)
问题是由破坏 RESTful 模式的 categoryID 参数给出的,DataManager 无法理解有一个参数。
可能的解决方案是将此参数作为 POST 变量发送,但 DataManager 无法做到这一点。
有人知道如何解决吗?这是现实世界应用程序中的常见场景。
在使用 ejDataManger 填充树网格数据时,CRUD 操作将使用内置 Post(插入)、Put(更新)、Delete 请求类型处理,而不管 CRUD URL。所以,删除记录不需要绑定‘removeUrl’。
并且,在提供的代码示例中,参数在 URL 中传递以获取数据,因此出现报告的问题。使用 ejQuery 的 addParams method we can pass the parameter in URL. You can find the code example to pass the parameter using Tree Grid load 事件并使用 DataManager 在服务器端检索参数。
[html]
var dataManager = ej.DataManager({
url: "api/Values",
adaptor: new ej.WebApiAdaptor()
});
$("#treeGridContainer").ejTreeGrid({
load: function (args) {
// to pass parameter on load time
args.model.query.addParams("keyId", 48);
},
});
[controller]
public object Get()
{
var queryString = HttpContext.Current.Request.QueryString;
// here we can get the parameter during load time
int num = Convert.ToInt32(queryString["keyId"]);
//..
return new {Items = DataList, Count = DataList.Count() };
}
您可以在此处找到 sample 以供参考。
此致,
Syncfusion 团队
我已经设置了一个 treeGrid(网格是相同的)以使用他们的 DataManager 通过 ASP.NET WebAPI 获取数据:
var categoryID=15;
var dataManager = ej.DataManager({
url: "/API/myrecords?categoryID=" + categoryID,
adaptor: new ej.WebApiAdaptor()
});
$("#treeGridContainer").ejTreeGrid({
dataSource: dataManager,
childMapping: "Children",
treeColumnIndex: 1,
isResponsive: true,
contextMenuSettings: {
showContextMenu: true,
contextMenuItems: ["add", "edit", "delete"]
},
contextMenuOpen: contextMenuOpen,
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal', editMode: "rowEditing" },
columns: [
{ field: "RecordID", headerText: "ID", allowEditing: false, width: 20, isPrimaryKey: true },
{ field: "RecordName", headerText: "Name", editType: "stringedit" },
],
actionBegin: function (args) {
console.log('ActionBegin: ', args);
if (args.requestType === "add") {
//add new record, managed manually...
var parentID = 0;
if (args.level != 0) {
parentID = args.parentItem.TaxonomyID;
}
args.data.TaxonomyID = 0;
addNewRecord(domainID, parentID, args.data, args.model.selectedRowIndex);
}
}
});
GET 工作完美。
PUT 工作正常,因为我手动管理它,因为它根本不是从 DataManager 调用的,无论如何我想管理 TreeGrid 中记录的更新。
问题出在 DELETE 上,当我从 TreeGrid 中某个项目的上下文菜单中单击“删除”时,DataManager 会调用它。
它调用以下 URL:
http://localhost:50604/API/myrecords?categoryID=15/undefined
显然,我得到一个 405(方法不允许)
问题是由破坏 RESTful 模式的 categoryID 参数给出的,DataManager 无法理解有一个参数。
可能的解决方案是将此参数作为 POST 变量发送,但 DataManager 无法做到这一点。
有人知道如何解决吗?这是现实世界应用程序中的常见场景。
在使用 ejDataManger 填充树网格数据时,CRUD 操作将使用内置 Post(插入)、Put(更新)、Delete 请求类型处理,而不管 CRUD URL。所以,删除记录不需要绑定‘removeUrl’。
并且,在提供的代码示例中,参数在 URL 中传递以获取数据,因此出现报告的问题。使用 ejQuery 的 addParams method we can pass the parameter in URL. You can find the code example to pass the parameter using Tree Grid load 事件并使用 DataManager 在服务器端检索参数。
[html]
var dataManager = ej.DataManager({
url: "api/Values",
adaptor: new ej.WebApiAdaptor()
});
$("#treeGridContainer").ejTreeGrid({
load: function (args) {
// to pass parameter on load time
args.model.query.addParams("keyId", 48);
},
});
[controller]
public object Get()
{
var queryString = HttpContext.Current.Request.QueryString;
// here we can get the parameter during load time
int num = Convert.ToInt32(queryString["keyId"]);
//..
return new {Items = DataList, Count = DataList.Count() };
}
您可以在此处找到 sample 以供参考。
此致,
Syncfusion 团队