Aggregation Rows Grid In Ext Gwt


Aggregation Rows Grid In Ext Gwt Sample Code 
  1.   
  2. package com.extjs.gxt.samples.client.examples.grid;  
  3.   
  4. import java.util.ArrayList;  
  5. import java.util.List;  
  6.   
  7. import com.extjs.gxt.samples.resources.client.TestData;  
  8. import com.extjs.gxt.samples.resources.client.model.Stock;  
  9. import com.extjs.gxt.ui.client.Style.HorizontalAlignment;  
  10. import com.extjs.gxt.ui.client.store.ListStore;  
  11. import com.extjs.gxt.ui.client.widget.ContentPanel;  
  12. import com.extjs.gxt.ui.client.widget.LayoutContainer;  
  13. import com.extjs.gxt.ui.client.widget.grid.AggregationRenderer;  
  14. import com.extjs.gxt.ui.client.widget.grid.AggregationRowConfig;  
  15. import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;  
  16. import com.extjs.gxt.ui.client.widget.grid.ColumnData;  
  17. import com.extjs.gxt.ui.client.widget.grid.ColumnModel;  
  18. import com.extjs.gxt.ui.client.widget.grid.Grid;  
  19. import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;  
  20. import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;  
  21. import com.extjs.gxt.ui.client.widget.grid.SummaryType;  
  22. import com.extjs.gxt.ui.client.widget.layout.FitLayout;  
  23. import com.extjs.gxt.ui.client.widget.layout.FlowLayout;  
  24. import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;  
  25. import com.google.gwt.i18n.client.DateTimeFormat;  
  26. import com.google.gwt.i18n.client.NumberFormat;  
  27. import com.google.gwt.user.client.Element;  
  28.   
  29. public class AggregationGridExample extends LayoutContainer {  
  30.   
  31.   @Override  
  32.   protected void onRender(Element parent, int index) {  
  33.     super.onRender(parent, index);  
  34.       
  35.     setLayout(new FlowLayout(15));  
  36.       
  37.     final NumberFormat currency = NumberFormat.getCurrencyFormat();  
  38.     final NumberFormat number = NumberFormat.getFormat("0.00");  
  39.     final NumberCellRenderer<Grid<Stock>> numberRenderer = new NumberCellRenderer<Grid<Stock>>(currency);  
  40.   
  41.     GridCellRenderer<Stock> change = new GridCellRenderer<Stock>() {  
  42.       public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,  
  43.           ListStore<Stock> store, Grid<Stock> grid) {  
  44.         double val = (Double)model.get(property);  
  45.         String style = val < 0 ? "red" : "green";  
  46.         return "<span style='color:" + style + "'>" + number.format(val) + "</span>";  
  47.       }  
  48.     };  
  49.   
  50.     GridCellRenderer<Stock> gridNumber = new GridCellRenderer<Stock>() {  
  51.       public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,  
  52.           ListStore<Stock> store, Grid<Stock> grid) {  
  53.         return numberRenderer.render(null, property, model.get(property));  
  54.       }  
  55.     };  
  56.   
  57.     List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  
  58.   
  59.     ColumnConfig column = new ColumnConfig();  
  60.     column.setId("name");  
  61.     column.setHeader("Company");  
  62.     column.setWidth(200);  
  63.     configs.add(column);  
  64.   
  65.     column = new ColumnConfig();  
  66.     column.setId("symbol");  
  67.     column.setHeader("Symbol");  
  68.     column.setWidth(100);  
  69.     configs.add(column);  
  70.   
  71.     column = new ColumnConfig();  
  72.     column.setId("last");  
  73.     column.setHeader("Last");  
  74.     column.setAlignment(HorizontalAlignment.RIGHT);  
  75.     column.setWidth(100);  
  76.     column.setRenderer(gridNumber);  
  77.     configs.add(column);  
  78.   
  79.     column = new ColumnConfig("change""Change"100);  
  80.     column.setAlignment(HorizontalAlignment.RIGHT);  
  81.     column.setRenderer(change);  
  82.     configs.add(column);  
  83.   
  84.     column = new ColumnConfig("date""Last Updated"100);  
  85.     column.setAlignment(HorizontalAlignment.RIGHT);  
  86.     column.setDateTimeFormat(DateTimeFormat.getFormat("MM/dd/yyyy"));  
  87.     configs.add(column);  
  88.   
  89.     final ListStore<Stock> store = new ListStore<Stock>();  
  90.     store.add(TestData.getStocks());  
  91.   
  92.     ColumnModel cm = new ColumnModel(configs);  
  93.       
  94.     cm.addHeaderGroup(02new HeaderGroupConfig("Stock Performance"12));  
  95.     cm.addHeaderGroup(00new HeaderGroupConfig("Stock Information"12));  
  96.    
  97.     AggregationRowConfig<Stock> averages = new AggregationRowConfig<Stock>();  
  98.     averages.setHtml("name""Average");  
  99.       
  100.     // with summary type and format  
  101.     averages.setSummaryType("last", SummaryType.AVG);  
  102.     averages.setSummaryFormat("last", NumberFormat.getCurrencyFormat());  
  103.       
  104.     // with renderer  
  105.     averages.setSummaryType("change", SummaryType.AVG);  
  106.     averages.setRenderer("change"new AggregationRenderer<Stock>() {  
  107.       public Object render(Number value, int colIndex, Grid<Stock> grid, ListStore<Stock> store) {  
  108.         // you can return html here  
  109.         return number.format(value.doubleValue());  
  110.       }  
  111.     });  
  112.     cm.addAggregationRow(averages);  
  113.       
  114.     averages = new AggregationRowConfig<Stock>();  
  115.     averages.setHtml("name""Maximum");  
  116.       
  117.       
  118.     averages.setSummaryType("last", SummaryType.MAX);  
  119.     averages.setSummaryFormat("last", NumberFormat.getCurrencyFormat());  
  120.   
  121.     averages.setSummaryType("change", SummaryType.MAX);  
  122.     averages.setRenderer("change"new AggregationRenderer<Stock>() {  
  123.       public Object render(Number value, int colIndex, Grid<Stock> grid, ListStore<Stock> store) {  
  124.         return number.format(value.doubleValue());  
  125.       }  
  126.     });  
  127.     cm.addAggregationRow(averages);  
  128.       
  129.     ContentPanel cp = new ContentPanel();  
  130.     cp.setCollapsible(true);  
  131.     cp.setAnimCollapse(false);  
  132.     cp.setFrame(true);  
  133.     cp.setHeading("Aggregation Rows");  
  134.     cp.setButtonAlign(HorizontalAlignment.CENTER);  
  135.     cp.setLayout(new FitLayout());  
  136.     cp.setBounds(1010600350);  
  137.   
  138.     Grid<Stock> grid = new Grid<Stock>(store, cm);  
  139.     grid.setBorders(false);  
  140.     grid.setAutoExpandColumn("name");  
  141.     grid.setBorders(true);  
  142.     cp.add(grid);  
  143.       
  144.     add(cp);  
  145.   }  
  146.     
  147. }  

Comments

Popular posts from this blog

Five More Indian Languages - Google Translate

Connect To JioFi Device Without Knowing The Passwords Using WPS