我有一个剑道网格,其中是一个开始日期字段。当为行更改“开始日期”字段时,我需要将同一行中另一个字段的值设置为null。
我在检测字段编辑时遇到问题
我已阅读Kendo UI documentation on datasource,特别是更改事件部分。它清楚了类型" itemchange"的更改事件。是我需要的。我觉得奇怪的是,当我更改“开始日期”字段时,唯一触发的事件是同步操作。值得注意的是,我的数据源中设置了autoSync:true。
对于上下文,这里有一些网格看起来像什么和数据源代码。任何建议都会非常感激。
var componentsDataSource = new kendo.data.DataSource({
autoSync: true,
transport: {
read: function (e) {
if ($scope.Booking.Components.length != 0) {
e.success($scope.Booking.Components);
}
else {
e.success([]);
}
},
update: function (e) {
e.success(e.data);
},
destroy: function (e) {
$scope.loadNotesForBooking();
e.success(e.data);
}
},
change: function (e) {
if (e.action === "itemchange") {
console.log("A itemchange happened");
console.log(e);
}
},
error: function (e) {
$log.error("ComponentsDataSource error:");
$log.error(e);
messageService.setError(e.xhr, "componentsDataSource.transport.error", e);
},
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false, nullable: false },
ProductCode: { editable: false, nullable: false },
Name: { editable: false, nullable: false },
Status: { editable: false, nullable: false },
Description: { editable: false, nullable: false },
UnitDescription: { editable: false, nullable: false },
StartDate: { type: "date", editable: true, nullable: false },
NumberOfAdults: { type: "number", editable: true, nullable: false, validation: { min: 0, required: true } },
NumberOfChildren: { type: "number", editable: true, nullable: false, validation: { min: 0, required: true } },
NumberOfInfants: { type: "number", editable: true, nullable: false, validation: { min: 0, required: true } },
Price: { editable: false, nullable: false },
PickupLocation: { editable: true, nullable: true },
DropoffLocation: { editable: true, nullable: true }
}
},
parse: function (response) {
if (response != null) {
$.each(response, function (i, item) {
if (item != null) {
//parse the data and convert the StartDate field (which comes through as a string) to a date so it can be formatted nicely by the grid
if (item.StartDate && typeof item.StartDate === "string") {
item.StartDate = kendo.parseDate(item.StartDate);
}
//build the description of the bus stops. This is done by the busStopData source for the dropdown lists but needs to be built here for any bookings being loaded
if (item.PickupLocation) {
if (item.PickupLocation.Code != "") {
item.PickupLocation.Description = item.PickupLocation.Name + " - " + item.PickupLocation.Time;
}
else {
item.PickupLocation.Description = "";
}
}
if (item.DropoffLocation) {
if (item.DropoffLocation.Code != "") {
item.DropoffLocation.Description = item.DropoffLocation.Name + " - " + item.DropoffLocation.Time;
}
else {
item.DropoffLocation.Description = "";
}
}
//add GUID style Ids to notes. This faciliates editing/deleting them from the grid as each can be uniquely identified
if (item.Remarks) {
if (item.Remarks.length > 0) {
$.each(item.Remarks, function (i, remark) {
if (!remark.Id) {
remark.Id = guid();
}
});
}
}
}
});
}
return response;
}
}
});