對於版本4.2,一個sorterFn可以在網格列marks
來限定。 sorterFn將被調用來進行排序時的比較。爲被比較的兩個學生該函數將計算標記的總數和返回-1,0或1,以指示其是較大的。
doSort: function (state) {
var store = this.up('grid').getStore();
var field = this.getSortParam();
var records = [];
store.each(function (r) {
records.push(r.copy());
});
store.sort({
property: field,
direction: state,
sorterFn: function (record1, record2) {
var total1 = 0,
total2 = 0;
records.forEach(function (rec) {
if (rec.data.studentID === record1.data.studentID)
total1 += rec.data.marks
});
records.forEach(function (rec) {
if (rec.data.studentID === record2.data.studentID)
total2 += rec.data.marks
});
return total1 > total2 ? 1 : (total1 < total2 ? -1 : 0)
}
});
}
See fiddle here示例實現你的網格。點擊標記列標題進行排序。
如果您正在使用ExtJS的,你可以在商店的標誌柱,以sorterFn加分選機:
store.sorters.items[0].setSorterFn(function (record1, record2) {
var total1 = 0,
total2 = 0;
records.forEach(function (rec) {
if (rec.data.studentID === record1.data.studentID)
total1 += rec.data.marks
});
records.forEach(function (rec) {
if (rec.data.studentID === record2.data.studentID)
total2 += rec.data.marks
});
return total1 > total2 ? 1 : (total1 < total2 ? -1 : 0)
});
有關創建分揀機功能的詳細信息,請參閱Sencha docs。
有關網格的示例實現,請參閱fiddle here。點擊標記列標題進行排序。
你是詢問網格總結? – Tejas
檢查了網格總結,但它並沒有解決我在網格中的目的,我們不想改變視圖。它仍然會顯示相同的學生ID多行。 – user2738606
你可以展示你是如何想通過圖片或樣品HTML? – Tejas