我有一个kendo heiarchy网格,我需要做的是当触发编辑功能时获取我正在编辑的当前行,然后根据该行获取相应的主行。
我的编辑功能
update: function(e) {
var campaignWeek = e.data.models[0]
$.ajax({
type: 'PUT',
data: {"campaign_week": campaignWeek },
url: "/campaign_week",
dataType: 'json',
success: function(data) {
e.success(data);
$(awesomeCampaignId.find('td')[4]).text(data.week_total_cost)
$(awesomeCampaignId.find('td')[5]).text(data.week_total_impressions)
$(awesomeCampaignId.find('td')[6]).text(data.week_total_grps)
},
});
},
我在e中获得的数据:
object {success: function, error: function, data: Object}
网格:
function campaignWeekGrid(e) {
var stationCampaignId = e.data.id
masterRow = e.masterRow
datasource = new kendo.data.DataSource({
transport: {
read: function(e) {
$.ajax({
type: 'GET',
url: "/station_campaigns/" + stationCampaignId + "/campaign_weeks",
dataType: 'json',
success: function(data) {
e.success(data);
},
});
},
update: function(e) {
var campaignWeek = e.data.models[0]
$.ajax({
type: 'PUT',
data: {"campaign_week": campaignWeek },
url: "/campaign_week",
dataType: 'json',
success: function(data) {
e.success(data);
$(masterRow.find('td')[4]).text(data.week_total_cost)
$(masterRow.find('td')[5]).text(data.week_total_impressions)
$(MasterRow.find('td')[6]).text(data.week_total_grps)
},
});
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
},
},
batch: true,
filterable: true,
schema: {
model: {
id: "id",
fields: {
date_range: { type: "string", editable: false },
cost: { type: "number" },
impressions: { type: "number" },
cost_per_thousands: { type: "number" },
}
}
},
});
$("<div>").appendTo(e.detailCell).kendoGrid({
dataSource: datasource,
height: 500,
resizable: true,
autoSync: false,
columns: [
{ field: "date_range", title: "Week", width: "175" },
{ field: "cost", title: "Cost" },
{ field: "impressions", title: "Impressions" },
{ field: "cost_per_thousands", title: "GRPs" },
{ command: ["destroy", "edit"], width: "100" },
],
editable: "inline"
});
}
我需要能够在更新函数中替换masterRow变量。所以我需要能够获取我正在编辑的当前行,然后获取相应的主行到该行。我一直在寻找一段时间,但找不到解决方案。真的很感激任何帮助。
答案 0 :(得分:0)
在kendo网格中,您可以在用户单击按钮时获取所选行:
// grid edit onclick function
$(document).ready(function ()
{
var grid = $("#gridName").data("kendoGrid");
$(grid.tbody).on("click", "td", function (e)
{
var row = $(this).closest("tr");
var rowIdx = $("tr", grid.tbody).index(row);
selectedRow = rowIdx;
});
}
答案 1 :(得分:0)
试试下面的代码,它对我有用。
var grid = e.sender;
var dataitem = grid.dataItem($(e.container).closest("tr"));
如果您认为这有帮助,请标记为答案。
感谢。