Skip to main content

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

Connect To JioFi Device Without Knowing The Passwords Using WPS

If someone in your home or your friends are using Jiofi device and he/she is not sharing the password with you then i am going to share you a simple trick, so you can easily connect to the jiofi router without the need of password and start using the unlimited internet.

This trick can be achieved using the WPS technology (Wi-Fi Protected Setup; originally, Wi-Fi Simple Config) is a network security standard to create a secure wireless home network.

Follow the steps to get the internet for free using the "WPS Push Button Method"
Go to your Wifi Settings in your smartphone device like Android Turn on your Wifi Click the option button and select the  "WPS push button" and you will be seeing the popup window like this below picture.
Now take your JioFi Device and in the right side, you will seeing the WPS button  Hold the WPS button for few moments and see the Jiofi display, so the wifi icon will blink. After few seconds, your smartphone device would have shared the Wifi…

Five More Indian Languages - Google Translate

Google Translate add 5 more indian language translation like Bengali, Gujarati, Kannada, Tamil and Telugu.Till Today Google Translation supports 63 languages. As a indian bloggger its a happy to announce that all indic languages sites and blogs become internationalized one. All indic bloggers and sites owners have to attach the google translate widgets to their sites so that the internationalized reader can realize the value of your blog and may be a chance of becoming the readers.



How to Add The Google Translate Widgets on Blog or Sites

Just Add the Below code to internationalized your blog or site

<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

If you want to customize the Goog…

Samsung Android 6.0 Marshmallow Supported Devices

Android Marshmallow is finally available. List of Samsung Device that can be upgraded to Android 6.0 Marshmallow.


Samsung Galaxy S6 edge+ Samsung Galaxy Note5Samsung Galaxy A8Samsung Galaxy A7Samsung Galaxy S6 edgeSamsung Galaxy S6Samsung Galaxy Note 4Samsung Galaxy AlphaSamsung Galaxy S5