GridUtil
Toolkit to simplify the use of the grid and adds missing features
This toolkil simplify the use of the grid and adds missing features
- introduce a easy way to build a filterrow
- add renderers that allows to display a combination of button and value within one cell (missing view/edit/delete button)
- shorten the lines of code for writing StringConverter
- add missing css-settings for cell alignment
The GridCellFilter-Component contains filters for the following types:
- String
- Date
- Number (checks if Integer, Long, Double...)
- Objects / Enums (via ComboBox with Equals-Filter)
- allows to add custom Filters and Components
For detailed code-example please take a look in the github demo-application. There I've tried to structure my code so that you can understand the usage and the features...
Sample code
package org.vaadin.gridutil.demo; import java.text.DateFormat; import java.util.Arrays; import java.util.Date; import java.util.Locale; import javax.servlet.annotation.WebServlet; import org.vaadin.gridutil.GridUtil; import org.vaadin.gridutil.cell.*; import org.vaadin.gridutil.converter.SimpleStringConverter; import org.vaadin.gridutil.demo.data.*; import org.vaadin.gridutil.renderer.*; import org.vaadin.gridutil.renderer.EditDeleteButtonValueRenderer.EditDeleteButtonClickListener; import com.vaadin.*; @Theme("valo") public class DemoUI extends UI { private GridCellFilter filter; @Override protected void init(final VaadinRequest request) { Grid grid = genGrid(); this.filter = new GridCellFilter(grid); this.filter.setNumberFilter("id"); // set gender Combo with custom icons ComboBox genderCombo = this.filter.setComboBoxFilter("gender", Arrays.asList(Gender.MALE, Gender.FEMALE)); genderCombo.setItemIcon(Gender.MALE, FontAwesome.MALE); genderCombo.setItemIcon(Gender.FEMALE, FontAwesome.FEMALE); // simple filters this.filter.setTextFilter("name", true, true); this.filter.setNumberFilter("bodySize"); this.filter.setDateFilter("birthday"); this.filter.setBooleanFilter("onFacebook"); // set country combo with custom caption ComboBox countryCombo = this.filter.setComboBoxFilter("country", DummyDataGen.COUNTRIES); countryCombo.setItemCaptionMode(ItemCaptionMode.PROPERTY); countryCombo.setItemCaptionPropertyId("name"); setContent(grid); } }
package org.vaadin.gridutil.demo; import java.text.DateFormat; import java.util.Arrays; import java.util.Date; import java.util.Locale; import javax.servlet.annotation.WebServlet; import org.vaadin.gridutil.GridUtil; import org.vaadin.gridutil.cell.*; import org.vaadin.gridutil.converter.SimpleStringConverter; import org.vaadin.gridutil.demo.data.*; import org.vaadin.gridutil.renderer.*; import org.vaadin.gridutil.renderer.EditDeleteButtonValueRenderer.EditDeleteButtonClickListener; import com.vaadin.*; @Theme("valo") public class DemoUI extends UI { private GridCellFilter filter; @Override protected void init(final VaadinRequest request) { Grid grid = genGrid(); grid.getColumn("id") .setRenderer(new EditDeleteButtonValueRenderer(new EditDeleteButtonClickListener() { @Override public void onEdit(final RendererClickEvent event) { Notification.show(event.getItemId() .toString() + " want's to get edited", Type.HUMANIZED_MESSAGE); } @Override public void onDelete(final com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent event) { Notification.show(event.getItemId() .toString() + " want's to get delete", Type.WARNING_MESSAGE); }; })) .setWidth(150); grid.getColumn("bodySize") .setWidth(150); grid.getColumn("birthday") .setRenderer(new DateRenderer(DateFormat.getDateInstance())) .setWidth(210); grid.getColumn("onFacebook") .setRenderer(new BooleanRenderer()) .setWidth(130); setContent(grid); } }
package org.vaadin.gridutil.demo; import java.text.DateFormat; import java.util.Arrays; import java.util.Date; import java.util.Locale; import javax.servlet.annotation.WebServlet; import org.vaadin.gridutil.GridUtil; import org.vaadin.gridutil.cell.*; import org.vaadin.gridutil.converter.SimpleStringConverter; import org.vaadin.gridutil.demo.data.*; import org.vaadin.gridutil.renderer.*; import org.vaadin.gridutil.renderer.EditDeleteButtonValueRenderer.EditDeleteButtonClickListener; import com.vaadin.*; @Theme("valo") public class DemoUI extends UI { private GridCellFilter filter; @Override protected void init(final VaadinRequest request) { Grid grid = genGrid(); grid.getColumn("country") .setConverter(new SimpleStringConverter<Country>(Country.class) { @Override public String convertToPresentation(final Country value, final Class<? extends String> targetType, final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return String.format("%s <i>(%d)</i>", value.getName(), value.getPopulation()); } }); setContent(grid); } }
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
- support getValueProvider thx to @oguzakp
- GridCellFilter without beanType thx to @Flamenco
- Released
- 2018-03-07
- Maturity
- EXPERIMENTAL
- License
- MIT License
Compatibility
- Framework
- Vaadin 8.1+
- Vaadin 7.4+ in 1.0.0
- Browser
- Browser Independent
GridUtil - Vaadin Add-on Directory
Toolkit to simplify the use of the grid and adds missing featuresIssue Tracker
Source Code
Online Demo
GridUtil version 1.0.0
initial version
GridUtil version 1.0.1
fixed a potential issue with diffent themes then valo
GridUtil version 1.0.2
changed visibilty of some function within CellFilterComponent and GridCellFilter to allow extending the layouts
started with a feature to change visibilty of FilterRow
* it's a deprecated function because there is still a issue the the connectors that of the cell-components that will not get propably cleand by removeing the hole HeaderRow
* you should use this feature with care because it will remove or repaints the hole HeaderRow because the grid itself has no feature to set visibility to rows. (css also not working because of absolute calculations within the grid)
GridUtil version 1.0.3
added support for inputPrompt
added support for custom FilterComponents (see demo and code)
GridUtil version 1.0.4
improved javadoc and added serializable
GridUtil version 1.0.5
added requested view button
GridUtil version 1.0.6
- added osgi support
- thx to philippberger
GridUtil version 1.0.7
some bugfixes and improvements
GridUtil version 1.0.8
* added value indicator (with ↑↓= and on hover display value)
* datefilter with same date works now
* minors fixes
GridUtil version 1.0.9
- fixed osgi support thx to philippberger
- fixed second bug in DateFilder thx to HapkiFighter
GridUtil version 1.0.10
* added support for custom dateFormat (thx to enver-haase)
* allow to specify if you would like to include or exclude endOfLastDay (Day + 23:59:59.999)
* some fixes
GridUtil version 1.1.0
**api-changed for GridCellFilter**
- setCellFilter now returns CellFilterComponent
- added getCellFilter to get CellFilterComponent
- with api-change it's possible to prefill filters
some minor improvements for i18n etc.
GridUtil version 2.1.0
- works now with vaadin 8.1
- great thanks to **hitchhiker-jiri** he has done a great job
GridUtil version 2.1.1
- support getValueProvider thx to @oguzakp
- GridCellFilter without beanType thx to @Flamenco