Skip to main content

Filter Grid In Ext GWT

Filter Grid In Ext GWT Sample code


  1. package com.extjs.gxt.samples.client.examples.grid;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import com.extjs.gxt.samples.resources.client.Resources;  
  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.GXT;  
  10. import com.extjs.gxt.ui.client.Style.HorizontalAlignment;  
  11. import com.extjs.gxt.ui.client.data.BaseModelData;  
  12. import com.extjs.gxt.ui.client.data.ModelData;  
  13. import com.extjs.gxt.ui.client.event.Events;  
  14. import com.extjs.gxt.ui.client.event.FieldEvent;  
  15. import com.extjs.gxt.ui.client.event.Listener;  
  16. import com.extjs.gxt.ui.client.store.ListStore;  
  17. import com.extjs.gxt.ui.client.widget.ContentPanel;  
  18. import com.extjs.gxt.ui.client.widget.LayoutContainer;  
  19. import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;  
  20. import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;  
  21. import com.extjs.gxt.ui.client.widget.grid.CellSelectionModel;  
  22. import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;  
  23. import com.extjs.gxt.ui.client.widget.grid.ColumnData;  
  24. import com.extjs.gxt.ui.client.widget.grid.ColumnModel;  
  25. import com.extjs.gxt.ui.client.widget.grid.Grid;  
  26. import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;  
  27. import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;  
  28. import com.extjs.gxt.ui.client.widget.grid.filters.BooleanFilter;  
  29. import com.extjs.gxt.ui.client.widget.grid.filters.DateFilter;  
  30. import com.extjs.gxt.ui.client.widget.grid.filters.GridFilters;  
  31. import com.extjs.gxt.ui.client.widget.grid.filters.ListFilter;  
  32. import com.extjs.gxt.ui.client.widget.grid.filters.NumericFilter;  
  33. import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter;  
  34. import com.extjs.gxt.ui.client.widget.layout.FitLayout;  
  35. import com.extjs.gxt.ui.client.widget.layout.FlowLayout;  
  36. import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;  
  37. import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;  
  38. import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;  
  39. import com.google.gwt.i18n.client.DateTimeFormat;  
  40. import com.google.gwt.i18n.client.NumberFormat;  
  41. import com.google.gwt.user.client.Element;  
  42.   
  43. public class FilterGridExample extends LayoutContainer {  
  44.   
  45.   @Override  
  46.   protected void onRender(Element parent, int index) {  
  47.     super.onRender(parent, index);  
  48.     setLayout(new FlowLayout(10));  
  49.     getAriaSupport().setPresentation(true);  
  50.   
  51.     final NumberFormat currency = NumberFormat.getCurrencyFormat();  
  52.     final NumberFormat number = NumberFormat.getFormat("0.00");  
  53.     final NumberCellRenderer<Grid<Stock>> numberRenderer = new NumberCellRenderer<Grid<Stock>>(currency);  
  54.   
  55.     GridCellRenderer<Stock> change = new GridCellRenderer<Stock>() {  
  56.       public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,  
  57.           ListStore<Stock> store, Grid<Stock> grid) {  
  58.         double val = (Double) model.get(property);  
  59.         String style = val < 0 ? "red" : GXT.isHighContrastMode ? "#00ff5a" : "green";  
  60.         return "<span style='font-weight: bold;color:" + style + "'>" + number.format(val) + "</span>";  
  61.       }  
  62.     };  
  63.   
  64.     GridCellRenderer<Stock> gridNumber = new GridCellRenderer<Stock>() {  
  65.       public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,  
  66.           ListStore<Stock> store, Grid<Stock> grid) {  
  67.         return numberRenderer.render(null, property, model.get(property));  
  68.       }  
  69.     };  
  70.   
  71.     List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  
  72.   
  73.     ColumnConfig column = new ColumnConfig();  
  74.     column.setId("name");  
  75.     column.setHeader("Company");  
  76.     column.setWidth(200);  
  77.     configs.add(column);  
  78.   
  79.     column = new ColumnConfig();  
  80.     column.setId("symbol");  
  81.     column.setHeader("Symbol");  
  82.     column.setWidth(100);  
  83.     configs.add(column);  
  84.   
  85.     column = new ColumnConfig();  
  86.     column.setId("last");  
  87.     column.setHeader("Last");  
  88.     column.setAlignment(HorizontalAlignment.RIGHT);  
  89.     column.setWidth(100);  
  90.     column.setRenderer(gridNumber);  
  91.     configs.add(column);  
  92.   
  93.     column = new ColumnConfig("change""Change"100);  
  94.     column.setAlignment(HorizontalAlignment.RIGHT);  
  95.     column.setRenderer(change);  
  96.     configs.add(column);  
  97.   
  98.     column = new ColumnConfig("date""Last Updated"100);  
  99.     column.setAlignment(HorizontalAlignment.RIGHT);  
  100.     column.setDateTimeFormat(DateTimeFormat.getFormat("MM/dd/yyyy"));  
  101.     configs.add(column);  
  102.   
  103.     column = new ColumnConfig("split""Split"75);  
  104.     column.setRenderer(new GridCellRenderer<Stock>() {  
  105.       public Object render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,  
  106.           ListStore<Stock> store, Grid<Stock> grid) {  
  107.         Boolean b = model.get(property);  
  108.         return b != null && b.booleanValue() ? "Yes" : "No";  
  109.       }  
  110.     });  
  111.     configs.add(column);  
  112.   
  113.     column = new ColumnConfig("type""Type"75);  
  114.     configs.add(column);  
  115.   
  116.     ListStore<Stock> store = new ListStore<Stock>();  
  117.     store.add(TestData.getStocks());  
  118.   
  119.     ColumnModel cm = new ColumnModel(configs);  
  120.   
  121.     ContentPanel cp = new ContentPanel();  
  122.     cp.setBodyBorder(true);  
  123.     cp.setIcon(Resources.ICONS.table());  
  124.     cp.setHeading("Filter Grid");  
  125.     cp.setButtonAlign(HorizontalAlignment.CENTER);  
  126.     cp.setLayout(new FitLayout());  
  127.     cp.setSize(660300);  
  128.   
  129.     GridFilters filters = new GridFilters();  
  130.     filters.setLocal(true);  
  131.   
  132.     NumericFilter last = new NumericFilter("last");  
  133.     NumericFilter filter = new NumericFilter("change");  
  134.     StringFilter nameFilter = new StringFilter("name");  
  135.     DateFilter dateFilter = new DateFilter("date");  
  136.     BooleanFilter booleanFilter = new BooleanFilter("split");  
  137.   
  138.     ListStore<ModelData> typeStore = new ListStore<ModelData>();  
  139.     typeStore.add(type("Auto"));  
  140.     typeStore.add(type("Media"));  
  141.     typeStore.add(type("Medical"));  
  142.     typeStore.add(type("Tech"));  
  143.     ListFilter listFilter = new ListFilter("type", typeStore);  
  144.     listFilter.setDisplayProperty("type");  
  145.   
  146.     filters.addFilter(last);  
  147.     filters.addFilter(nameFilter);  
  148.     filters.addFilter(filter);  
  149.     filters.addFilter(dateFilter);  
  150.     filters.addFilter(booleanFilter);  
  151.     filters.addFilter(listFilter);  
  152.   
  153.     final Grid<Stock> grid = new Grid<Stock>(store, cm);  
  154.     grid.getView().setForceFit(true);  
  155.     grid.setStyleAttribute("borderTop""none");  
  156.     grid.setAutoExpandColumn("name");  
  157.     grid.setBorders(false);  
  158.     grid.setStripeRows(true);  
  159.     grid.setColumnLines(true);  
  160.     grid.addPlugin(filters);  
  161.     cp.add(grid);  
  162.   
  163.     ToolBar toolBar = new ToolBar();  
  164.     toolBar.getAriaSupport().setLabel("Grid Options");  
  165.   
  166.     toolBar.add(new LabelToolItem("Selection Mode: "));  
  167.     final SimpleComboBox<String> type = new SimpleComboBox<String>();  
  168.     type.setTriggerAction(TriggerAction.ALL);  
  169.     type.setEditable(false);  
  170.     type.setFireChangeEventOnSetValue(true);  
  171.     type.setWidth(100);  
  172.     type.add("Row");  
  173.     type.add("Cell");  
  174.     type.setSimpleValue("Row");  
  175.     type.addListener(Events.Change, new Listener<FieldEvent>() {  
  176.       public void handleEvent(FieldEvent be) {  
  177.         boolean cell = type.getSimpleValue().equals("Cell");  
  178.         grid.getSelectionModel().deselectAll();  
  179.         if (cell) {  
  180.           grid.setSelectionModel(new CellSelectionModel<Stock>());  
  181.         } else {  
  182.           grid.setSelectionModel(new GridSelectionModel<Stock>());  
  183.         }  
  184.       }  
  185.     });  
  186.     toolBar.add(type);  
  187.     cp.setTopComponent(toolBar);  
  188.     add(cp);  
  189.   }  
  190.   
  191.   private ModelData type(String type) {  
  192.     ModelData model = new BaseModelData();  
  193.     model.set("type", type);  
  194.     return model;  
  195.   }  
  196.   
  197. }  

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