我在PivotGrid遇到问题,其中网格引发错误:“无法读取Kendo Pivot Grid MVC中未定义的属性'value'”。这种行为并非每次都会发生。 我设置了一个超时功能,以为数据可能还没有发送出去。我尝试重写所有JavaScript。似乎没有任何作用。
你们有什么建议吗?谢谢
PivotGrid的声明:
@(Html.Kendo().PivotGrid<RfpPurchasePrice>()
.Name("pivotPurchasePrices")
//.Events(x => x.DataBound("autoSizePivot"))
.AutoBind(false)
.Excel(excel => excel
.FileName("historialPrices_" + DateTime.Now.ToShortTimeString() + ".xlsx")
)
.ColumnWidth(75)
.Height(315)
.DataSource(dataSource => dataSource
.Ajax()
.Transport(transport => transport.Read("GetRfpPurchasePrices", "RFPCosting"))
.Events(x=>x.Error("pivotError"))
.Schema(schema => schema
.Cube(cube => cube
.Dimensions(dimensions =>
{
dimensions.Add(model => model.Month).Caption("Month");
dimensions.Add(model => model.Year).Caption("Year");
dimensions.Add(model => model.VendorName).Caption("Vendor");
dimensions.Add(model => model.ProductCost).Caption("ProductCost");
dimensions.Add(model => model.ReceiveQuantity).Caption("ReceiveQuantity");
})
.Measures(
measures =>
{
measures.Add("CostSum").Format("{0:c}").Aggregate("CalculateCost");
}
)
))
.Columns(columns =>
{
columns.Add("Month").Expand(true);
})
.Rows(rows =>
{
rows.Add("Year");
rows.Add("VendorName").Expand(true);
})
.Measures(measures => measures.Values("CostSum"))
)
)
具有动态字段的数据表:
var counter = 0;
//Setup data tables for season input values
var t = $('#tblAddSeason').DataTable({
"paging": false,
"ordering": false,
"scrollX": true,
"info": false,
"searching": false,
"scrollY": '300px',
"scrollCollapse": true
});
添加行的功能:
$('#btnAddRow').on('click', function (e) {
e.preventDefault();
t.row.add([
"<input style='width: 115px' type='text' id='models[" + counter + "].SeasonStart' name='models[" + counter + "].SeasonStart' />",
"<input style='width: 115px' type='text' id='models[" + counter + "].SeasonEnd' name='models[" + counter + "].SeasonEnd' />",
"<input id='models[" + counter + "].GrowingRegion' name='models[" + counter + "].GrowingRegion'/>",
"<input style='width: 75px' id='models[" + counter + "].Warehouse' name='models[" + counter + "].Warehouse'/>",
"<input style='width: 75px' id='models[" + counter + "].Repack' name='models[" + counter + "].Repack'/>",
"<input id='models[" + counter + "].InputProduct' name='models[" + counter + "].InputProduct'/>",
"<input id='models[" + counter + "].OutputProduct' name='models[" + counter + "].OutputProduct'/>",
"<button class='btn btn-success'>Fetch</button>",
"<input autocomplete='false' type='text' class='form-control cssOverride' id='models[" + counter + "].FobCost' name='models[" + counter + "].FobCost' />",
"<input autocomplete='false' type='text' class='form-control cssOverride' id='models[" + counter + "].InboundFreightCost' name='models[" + counter + "].InboundFreightCost' />",
"<input autocomplete='false' type='text' class='form-control cssOverride' id='models[" + counter + "].WHCharge' name='models[" + counter + "].WHCharge' />",
"<input autocomplete='false' type='text' class='form-control cssOverride' id='models[" + counter + "].RepackCharge' name='models[" + counter + "].RepackCharge' />",
"<input autocomplete='false' type='text' class='form-control cssOverride' id='models[" + counter + "].PackingMaterials' name='models[" + counter + "].PackingMaterials' />",
"<input autocomplete='false' type='text' class='form-control cssOverride' id='models[" + counter + "].Shrink' name='models[" + counter + "].Shrink' />"
]).draw(false);
当用户点击“获取”按钮时,将触发此功能。它获取一些参数,并将其输入到枢轴网格的数据源。这有时会起作用,但并非每次都起作用。如果我更改月份日期选择器或某些下拉菜单,它可能会停止工作,但不一致。
Javascript:
$('#tblAddSeason tbody').on('click', 'button', function (e) {
e.preventDefault();
//Find row index
var idx = t.row($(this).parents('tr')).index();
//Find datepicker season month selection
var start = t.cell(idx, 0).nodes().to$().find('input').val();
var end = t.cell(idx, 1).nodes().to$().find('input').val();
var prodId = t.cell(idx, 5).nodes().to$().find('input').val();
//Convert month name 'JAN' to integer 1
startMonth = getMonthFromString(start)
endMonth = getMonthFromString(end)
var data = {
prodId: prodId,
month1: startMonth,
month2: endMonth
}
if (prodId && startMonth && endMonth) {
$("#pivotPurchasePrices").data("kendoPivotGrid").dataSource.data([]);
$("#pivotUsdaData").data("kendoPivotGrid").dataSource.data([]);
var pivotPrices = $("#pivotPurchasePrices").data("kendoPivotGrid");
pivotPrices.dataSource.read(data);
var pivotUsda = $("#pivotUsdaData").data("kendoPivotGrid");
pivotUsda.dataSource.read(data);
$("#exportUsda").fadeIn();
$("#exportHistory").fadeIn();
$("#pivotPurchasePrices").fadeIn();
$("#pivotUsdaData").fadeIn();
$(".pricingHeaders").fadeIn();
$.ajax({
type: "POST",
url: "/RFPCosting/GetUSDAProduct",
data: data,
dataType: "json",
success: function (response) {
$('#lblUsdaProduct').html(response);
}
});
}
});
引发错误时:
kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1 Uncaught TypeError: Cannot read property 'value' of undefined
at init._buildRow (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init._buildRows (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init._tbody (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init.build (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init.refresh (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init.f (jquery.min.js:2)
at init.trigger (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init._process (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init.success (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
at init.success (kendo?v=UrrZxjxAYh2OzBW5awHWSPND63FEZBQZyo1oU36iL4Y1:1)
这个人似乎有完全相同的问题,但没有人发布答案: Cannot read property 'value' of undefined in Kendo Pivot Grid MVC
答案 0 :(得分:0)
在pivotUsda.dataSource.read(data);
之前添加此pivotUsda.dataSource.trigger("stateReset");
。
像这样:
if (prodId && startMonth && endMonth) {
$("#pivotPurchasePrices").data("kendoPivotGrid").dataSource.data([]);
$("#pivotUsdaData").data("kendoPivotGrid").dataSource.data([]);
var pivotPrices = $("#pivotPurchasePrices").data("kendoPivotGrid");
pivotPrices.dataSource.trigger("stateReset");
pivotPrices.dataSource.read(data);
var pivotUsda = $("#pivotUsdaData").data("kendoPivotGrid");
pivotUsda.dataSource.trigger("stateReset");
pivotUsda.dataSource.read(data);
$("#exportUsda").fadeIn();
$("#exportHistory").fadeIn();
$("#pivotPurchasePrices").fadeIn();
$("#pivotUsdaData").fadeIn();
$(".pricingHeaders").fadeIn();
$.ajax({
type: "POST",
url: "/RFPCosting/GetUSDAProduct",
data: data,
dataType: "json",
success: function (response) {
$('#lblUsdaProduct').html(response);
}
});
}
经过反复试验和深入研究,终于在KendoUI文档here
中找到了解决方案