我已经设置了一个基本的Kendo Grid,我正在使用服务器端的PHP Wrapper库中的DataSourceResult类.
我遇到了一个奇怪的问题...如果我create
是一个新记录然后编辑它(没有刷新页面),create
则再次调用该操作,而不是update
操作.
如果在添加新记录后刷新页面,则update
在更改记录后将正确调用该操作.
我可以确认DataSourceResult类在create
操作后返回正确的数据,包括id
新记录.
任何想法为什么会发生这种情况(以及如何阻止它)?谢谢
更新:这是数据源代码.网址中的查询字符串只是为了轻松区分Chrome控制台中的请求.每个请求传递的附加数据用于ajax.php
区分请求的不同操作.
data = new kendo.data.DataSource({ transport: { create: { url: '/ajax.php?r=gridCreate', dataType: 'json', type: 'post', data: { request: 'grid', type: 'create' } }, read: { url: '/ajax.php?request=gridRead', dataType: 'json', type: 'post', data: { request: 'grid', type: 'read' } }, update: { url: '/ajax.php?r=gridUpdate', dataType: 'json', type: 'post', data: { request: 'grid', type: 'update' } }, destroy: { url: '/ajax.php?r=gridDestroy', dataType: 'json', type: 'post', data: { request: 'grid', type: 'destroy' } }, parameterMap: function(data, operation) { if (operation != "read"){ data.expires = moment(data.expires).format('YYYY-MM-DD HH:mm'); } return data; } }, schema: { data: 'data', total: 'total', model: { id: 'id', fields: { id: { editable: false, nullable: true }, code: { type: 'string' }, expires: { type: 'date' }, enabled: { type: 'boolean', defaultValue: true } } } }, pageSize: 30, serverPaging: true, serverSorting: true, serverFiltering: true });
小智.. 6
最佳方案
设置为更新,创建或删除不同的"呼叫操作"
来自Telerik支持:
我已经在您提交的相同主题的支持主题中回复了您的问题.为方便起见,我也会在论坛上粘贴我的回复.
出现此问题的原因是您的模型没有ID.模型ID对于编辑功能至关重要,不应忽略 - 每个dataSource记录应具有唯一ID,具有空ID字段的记录被视为新记录,并通过"create"传输提交.
schema: { model: { //id? model must have an unique ID field fields: { FirstName: { editable: false}, DOB: { type: "date"}, Created: {type: "date" }, Updated: {type: "date" }, } } },
有关该主题的更多信息,请检查以下资源:
http://docs.kendoui.com/api/framework/model#methods-Model.define http://www.kendoui.com/forums/ui/grid/request-for-support-on-editable-grid.aspx #228oGIheFkGD4v0SkV8Fzw
元富
我希望这些信息会有所帮助
Herin.. 5
我也有同样的问题,我试过这个,它会工作.
.Events(events => events.RequestEnd("onRequestEnd"))
在这个功能中使用下面:
function onRequestEnd(e) { var tmp = e.type; if (tmp == "create") { //RequestEnd event handler code alert("Created succesully"); var dataSource = this; dataSource.read(); } else if (tmp == "update") { alert("Updated succesully"); } }
尝试在网格的onRequestEnd事件中使用此代码
var dataSource = this; dataSource.read();
希望它能帮到你.
我也有同样的问题,我试过这个,它会工作.
.Events(events => events.RequestEnd("onRequestEnd"))
在这个功能中使用下面:
function onRequestEnd(e) { var tmp = e.type; if (tmp == "create") { //RequestEnd event handler code alert("Created succesully"); var dataSource = this; dataSource.read(); } else if (tmp == "update") { alert("Updated succesully"); } }
尝试在网格的onRequestEnd事件中使用此代码
var dataSource = this; dataSource.read();
希望它能帮到你.
最佳方案
设置为更新,创建或删除不同的"呼叫操作"
来自Telerik支持:
我已经在您提交的相同主题的支持主题中回复了您的问题.为方便起见,我也会在论坛上粘贴我的回复.
出现此问题的原因是您的模型没有ID.模型ID对于编辑功能至关重要,不应忽略 - 每个dataSource记录应具有唯一ID,具有空ID字段的记录被视为新记录,并通过"create"传输提交.
schema: { model: { //id? model must have an unique ID field fields: { FirstName: { editable: false}, DOB: { type: "date"}, Created: {type: "date" }, Updated: {type: "date" }, } } },
有关该主题的更多信息,请检查以下资源:
http://docs.kendoui.com/api/framework/model#methods-Model.define http://www.kendoui.com/forums/ui/grid/request-for-support-on-editable-grid.aspx #228oGIheFkGD4v0SkV8Fzw
元富
我希望这些信息会有所帮助