2017-05-23 21 views
0

例如 - 有一個extjs網格,其中顯示以下字段: Student Id,Subject and馬克斯在extjs網格4.2.1中,有沒有一種方法來計算rowspan,並基於相同的列值計算兩行(列數據)的總和

現在同樣的學生ID爲不同的主題都會有不同的標記,我們必須通過標記,這樣它將計算總標記爲特定的學生證和排序佔總分排序。

對我們如何才能在Ext JS中實現它有什麼建議? Sample Example Image

+0

你是詢問網格總結? – Tejas

+0

檢查了網格總結,但它並沒有解決我在網格中的目的,我們不想改變視圖。它仍然會顯示相同的學生ID多行。 – user2738606

+0

你可以展示你是如何想通過圖片或樣品HTML? – Tejas

回答

0

對於版本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。點擊標記列標題進行排序。

相關問題