當顯示組彙總值時,使用Syncfusion ejGrid和knockout.js時出現問題,並且以空網格開始或向現有網格動態添加元素時出現問題。顯示彙總行時Syncfusion ejGrid和knockout.js的問題
網格設置:
<div id="Grid" data-bind="ejGrid: {
dataSource: dataSource,
allowGrouping:true,
allowSorting:true,
columns: [{ field: 'OrderID', headerText: 'OrderID' },
{ field: 'CustomerID', headerText: 'CustomerID' },
{ field: 'ShipCity', headerText: 'ShipCity' },
{ field: 'Freight', headerText: 'Freight' },
{ field: 'EmployeeID', headerText: 'EmployeeID' }
],
showSummary: true,
summaryRows: [
{ summaryColumns: [{
summaryType: ej.Grid.SummaryType.Sum,
displayColumn: 'Freight',
dataMember: 'Freight',
prefix: 'Total: '
}],
showCaptionSummary: true,
showTotalSummary: false
}
],
}">
</div>
初始化:
var rows = [{
OrderID: 10248,
CustomerID: "VINET",
ShipCity: "Reims",
Freight: 11.61,
EmployeeID: 4
}, {
OrderID: 10250,
CustomerID: "HANAR",
ShipCity: "Charleroi",
Freight: 65.83,
EmployeeID: 2
}, {
OrderID: 10251,
CustomerID: "VICTE",
ShipCity: "Reims",
Freight: 41.34,
EmployeeID: 1
}, {
OrderID: 10252,
CustomerID: "SUPRD",
ShipCity: "Madrid",
Freight: 51.3,
EmployeeID: 3
}, {
OrderID: 10253,
CustomerID: "HANAR",
ShipCity: "Rio de Janeiro",
Freight: 58.17,
EmployeeID: 3
}];
var source = ko.observableArray(rows);
var gridData = {
dataSource: source
};
ko.applyBindings(gridData);
現在,下面的jsfiddle工作正常。也就是說,如果將'CustomerID'列拖入分組區域,每個組的摘要值(標記爲「總計」)顯示爲正常:http://jsfiddle.net/zxw5sL2m/1/
現在,如果網格最初爲空,然後添加了行,在ej.web.all-latest.min.js:http://jsfiddle.net/zxw5sL2m/2/中加載'TypeError:r is undefined'時失敗(另外,如果刪除knockout.js,則此方案不起作用:http://jsfiddle.net/ymgkf7r9/)
同樣,如果網格最初是非空的,然後添加行,則它加載正常,但是當應用分組時,它會在ej.web.all-latest.min.js中的'TypeError:y is null'失敗: http://jsfiddle.net/zxw5sL2m/3/
如果不包括組摘要,則錯誤消失:http://jsfiddle.net/zxw5sL2m/4/
設置showCaptionSummary: false
排序作品,但是每次添加新行(在任何分組之前),新的摘要行也會添加到底部而不是更新現有的彙總行:http://jsfiddle.net/zxw5sL2m/5/
此外,如果網格按列開始分組,然後添加行,則會正確更新組:http://jsfiddle.net/zxw5sL2m/8/但是,如果網格最初未組合,然後再進行分組(無論是由用戶還是通過調用gridColumn
方法),當新行添加到網格時,分組會丟失(儘管奇怪的是組列名仍出現在組區域中在頭):http://jsfiddle.net/zxw5sL2m/9/
我發現在你的啓動空例如,如果你設置'showCaptionSummary'爲false,沒有錯誤。 http://jsfiddle.net/zxw5sL2m/5/ 它也解決了最後一個例子。我無法解釋爲什麼。 –