Javascript Telerik剑道网格从模板获取行详细信息
我正在一个.NET项目中使用带MVC的剑道网格。“我的网格”的两列是模板,它们在模板内部有一个输入文本。这样,每次网格加载时,输入文本总是可见的,并且可以进行更改 当用户单击save时,我需要在客户端检查网格的所有行,并获取这两列的值(只有两列有模板)和输入框的值。因此,我期望的结果是一个包含两列的列表,其中包含用户在输入框中插入的最后一个值,而不是原始值 这是我的密码:Javascript Telerik剑道网格从模板获取行详细信息,javascript,jquery,kendo-ui,kendo-grid,kendo-asp.net-mvc,Javascript,Jquery,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,我正在一个.NET项目中使用带MVC的剑道网格。“我的网格”的两列是模板,它们在模板内部有一个输入文本。这样,每次网格加载时,输入文本总是可见的,并且可以进行更改 当用户单击save时,我需要在客户端检查网格的所有行,并获取这两列的值(只有两列有模板)和输入框的值。因此,我期望的结果是一个包含两列的列表,其中包含用户在输入框中插入的最后一个值,而不是原始值 这是我的密码: //Grid Data source var dataSource = new kendo.data.DataSource(
//Grid Data source
var dataSource = new kendo.data.DataSource({
transport: {
read: { url: "/CsmForecastRegistration/GetForecast", cache: false }
},
error: function (e) {
openDialog(e.errorThrown);
},
batch: true,
pageSize: 20,
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "ForecastItemId",
fields: {
ForecastItemId: { editable: false },
RecordId: { editable: false },
SaleId: { editable: false },
IsUpSell: { editable: false },
BusinessName: { editable: false },
HealthScore: { editable: false },
CurrencySymbol: { editable: false },
ForecastWeekTotalContractValue: { editable: true },
ForecastWeekMonths: { editable: true },
ForecastWeek12Months: { editable: false }
}
}
}
});
$("#grdCsmForecast").kendoGrid({
dataSource: dataSource,
scrollable: true,
dataBound: onDataBound,
toolbar: ["excel"],
excel: {
allPages: true,
fileName: "CSMForecast.xlsx"
},
pageable: true,
columns: [
{ title: "", width: "80px", template: $("#comments-template").html(), attributes: { style: "text-align:center; background-color: white;" } },
{
title: "Contract Details",
columns: [
{ field: "RecordId", title: "RecordId", width: "90px", attributes: { "class": "contractDetailGridStyle" } },
{ field: "SaleId", title: "SaleId", width: "90px", attributes: { "class": "contractDetailGridStyle" } },
{ field: "IsUpSell", title: "Upsell?", width: "75px", attributes: { "class": "contractDetailGridStyle" } },
{ field: "BusinessName", title: "Business Name", width: "250px", attributes: { "class": "contractDetailGridStyle"} },
{ field: "HealthScore", title: "Health Score", width: "95px", attributes: { "class": "contractDetailGridStyle"} },
{ field: "CurrencySymbol", title: "CCY", width: "50px", attributes: { "class": "contractDetailGridStyle" } }
]
},
{
title: "Forecast Week",
columns: [
{ field: "ForecastWeekTotalContractValue", title: "TCV", width: "75px", template: $("#forecast-week-tcv").html(), attributes: { "class": "forecastWeekGridStyle" }, footerTemplate: "#: sum # " },
{ field: "ForecastWeekMonths", title: "Months", width: "70px", template: $("#forecast-weekMonths").html(), attributes: { "class": "forecastWeekGridStyle" } },
{ field: "ForecastWeek12Months", title: "12Month", width: "75px", attributes: { "class": "forecastWeekGridStyle" }, footerTemplate: "#: sum # " }
]
}
]
});
以及模板:
<script id="forecast-week-tcv" type="text/x-kendo-template">
# if(IsNewContract === true ){ #
<span>#=ForecastWeekTotalContractValue#</span>
#}
else{#
<input type="text" value="#=ForecastWeekTotalContractValue#" />
#}#
</script>
<script id="forecast-weekMonths" type="text/x-kendo-template">
# if(IsNewContract === true ){ #
<span>#=ForecastWeekMonths#</span>
#}
else{#
<input type="text" value="#=ForecastWeekMonths#" />
#}#
</script>
#如果(IsNewContract==true){#
#=预测周总合同价值#
#}
否则{#
#}#
#如果(IsNewContract==true){#
#=预测周数#
#}
否则{#
#}#
因此,我想要一个列表,并将这两个输入的所有值发送给我的MVC控制器:
<input type="text" value="#=ForecastWeekTotalContractValue#" />
<input type="text" value="#=ForecastWeekMonths#" />
谢谢试试这样的方法:
function getInputValues() {
let result = [];
$('#grid tbody tr').each((i, tr) => {
let row = {};
$(tr).find('input[type="text"]').each((index, input) => {
row[(index ? "ForecastWeekTotalContractValue" : "ForecastWeekMonths")] = $(input).val();
});
result.push(row);
});
return result;
}
它只是在元素上迭代并添加到对象数组中。谢谢,这正是我需要的!干得好。@MarcosF8太好了!!