summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Lumme <erik@vaadin.com>2017-09-15 13:34:50 +0300
committerErik Lumme <erik@vaadin.com>2017-09-15 13:34:50 +0300
commitd5ed5053222cd02d2287c2d64759ffb4247763ba (patch)
treeed400c479c0800ac40dffe512fe13f4151e1c322
parentd4a822eccba4a9f662a72ea9c3f6194592c4a7aa (diff)
downloadvaadin-framework-d5ed5053222cd02d2287c2d64759ffb4247763ba.tar.gz
vaadin-framework-d5ed5053222cd02d2287c2d64759ffb4247763ba.zip
Migrate UsingGridWithAContainer
-rw-r--r--documentation/articles/UsingGridWithAContainer.asciidoc107
-rw-r--r--documentation/articles/contents.asciidoc1
2 files changed, 108 insertions, 0 deletions
diff --git a/documentation/articles/UsingGridWithAContainer.asciidoc b/documentation/articles/UsingGridWithAContainer.asciidoc
new file mode 100644
index 0000000000..5782c698ed
--- /dev/null
+++ b/documentation/articles/UsingGridWithAContainer.asciidoc
@@ -0,0 +1,107 @@
+[[using-grid-with-a-container]]
+Using Grid with a Container
+---------------------------
+
+Grid lazy-loads data from a `Container` instance. There are different
+container implementations that e.g. fetch data from a database or use a
+list of Java objects. Assuming you already have code that initializes a
+`Container`, this is all that is needed for showing a Grid with the data
+from your container.
+
+[source,java]
+....
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.UI;
+
+public class UsingGridWithAContainer extends UI {
+ @Override
+ protected void init(VaadinRequest request) {
+ Grid grid = new Grid();
+ grid.setContainerDataSource(GridExampleHelper.createContainer());
+
+ setContent(grid);
+ }
+}
+....
+
+The container in this example contains three properties; name, count and
+amount. You can configure the columns in Grid using the property ids to
+do things like setting the column caption, removing a column or changing
+the order of the visible columns.
+
+[source,java]
+....
+protected void init(VaadinRequest request) {
+ Grid grid = new Grid();
+ grid.setContainerDataSource(GridExampleHelper.createContainer());
+
+ grid.getColumn("name").setHeaderCaption("Bean name");
+ grid.removeColumn("count");
+ grid.setColumnOrder("name", "amount");
+
+ setContent(grid);
+}
+....
+
+This is really all that is needed to get started with Grid.
+
+For reference, this is how the example container is implemented.
+
+[source,java]
+....
+public class GridExampleBean {
+ private String name;
+ private int count;
+ private double amount;
+
+ public GridExampleBean() {
+ }
+
+ public GridExampleBean(String name, int count, double amount) {
+ this.name = name;
+ this.count = count;
+ this.amount = amount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+}
+....
+
+[source,java]
+....
+import com.vaadin.data.util.BeanItemContainer;
+
+public class GridExampleHelper {
+ public static BeanItemContainer<GridExampleBean> createContainer() {
+ BeanItemContainer<GridExampleBean> container = new BeanItemContainer<GridExampleBean>(
+ GridExampleBean.class);
+ for (int i = 0; i < 1000; i++) {
+ container.addItem(new GridExampleBean("Bean " + i, i * i, i / 10d));
+ }
+ return container;
+ }
+}
+....
diff --git a/documentation/articles/contents.asciidoc b/documentation/articles/contents.asciidoc
index a356c99b4b..c03bbe214d 100644
--- a/documentation/articles/contents.asciidoc
+++ b/documentation/articles/contents.asciidoc
@@ -31,3 +31,4 @@
- link:CreatingAMasterDetailsViewForEditingPersons.asciidoc[Creating a master details view for editing persons]
- link:ShowingExtraDataForGridRows.asciidoc[Showing extra data for Grid rows]
- link:CreatingATextFieldForIntegerOnlyInputUsingADataSource.asciidoc[Creating a TextField for integer only input using a data source]
+- link:UsingGridWithAContainer.asciidoc[Using Grid with a Container]