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(660, 300);  
  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

Gradle project sync failed. Basic functionality (e.g, editing, debugging) will not work properly.

Gradle is an open source build tool which help us to accelerate developer productivity. Go to Gradle Services website(http://services.gradle.org/distributions/) and download the latest version Download the latest version gradle-4.7-rc-1-all.zip ( Latest version while writing this article) and you can download greater than 4.7 if available and make sure the zip file contains "all" keyword (gradle-*.*-rc-*-all.zip). Go to your download location and unzip the downloaded file Android Studio > File >  Settings > Build, Execution, Deployment  Gradle Project-level settings -> Select Use local gradle distribution -> Select the unzip folder of downloaded gradle version -> Click OK button to exit from the Settings window. Please Wait until Gradle build completes and your problem have been resolved.   If gradle build failed, follow few more steps to get resolved Final step to resolve this error Go to your project -> Gradle script -...

How to Send Secured Data in Internet - Steganography

Image Description: Hackers Growth of Science and Technology finds innovative ways to find patches over attacks made by hacker.In the Internet there are millions of computer are interconnected by network.If some people want to share some personal things like bank accounts or premium login accounts through email or any other share media but hacker who is surfing anonymously in the Internet find the personal documents and trying to modify the original message as well utilizing the original message so that the receiver who receive fake message from hacker thought that the message sended by sender.. In order to confuse hackers technology made another innovation in new technique called "Steganography" What is Steganography? Steganography is new technology innovation which hides text messages in image,audio,text and video files To Make your data very securely just what you need to do is find the best steganography software from Internet and download it and then encrypt your me...

Spring Boot GraphQL Save, Update and Delete - Database MutationMapping

Learn how to get started with Graphql using spring boot framework. In this session, you will be learning like how to add the schema details and mapping the function and request payload with Graphql @MutationMapping into your controller class. So you can preform like Save, update and delete operation using graphql You need Spring web, JPA, Mysql, Lombok and Spring Graphql dependencies to your pom module. schema.graphqls (This file should be created inside the resources/graphql folder) type Query{ findAll: [User] userById(id: ID): User } type User{ id: ID name: String gender: String emailId: String } type Mutation{ addUser(userDetails: UserDetails): User updateUser(userDetails: UserDetails): User deleteUser(id: ID): String } input UserDetails{ id: ID name: String gender: String emailId: String } UserGQLController .java package com.hakeemit.graphql.controller; import com.hakeemit.graphql.entity.User; import com.hakeemit.gra...