vaadin7 - Add sub header row / summarizing row in Vaadin Grid -
is possible add summarizing row vaadin grid?
i have grid has header row join columns , give overview @ top. however, add similar headers throughout grid in order mark end of section. appears possible add headers in header section fill head of grid. footers same @ bottom.
but if want special row within grid without having create new grid component? 1 visible data separator.
depending on need , how complicated app is, can fake
(possibly minor) effort. can find below simple example should started.
1) common class use beanitemcontainer
display both categories of rows
public abstract class row { private string name; private int amount; public row(string name, int amount) { this.name = name; this.amount = amount; } public string getname() { return name; } public void setname(string name) { this.name = name; } public int getamount() { return amount; } public void setamount(int amount) { this.amount = amount; } // provide custom style/type current row public abstract string getrowtype(); }
2) regular product row
public class productrow extends row { public productrow(string name, int amount) { super(name, amount); } @override public string getrowtype() { return "product-row"; } }
3) special row display total previous batch of products
public class totalrow extends row { public totalrow(int sum) { super("total", sum); } @override public string getrowtype() { return "total-row"; } }
4) grid itself
public class gridwithintermediaterowscomponent extends verticallayout { private static final string[] available_products = new string[]{"banana", "apple", "coconut", "pineapple", "melon"}; private random random = new random(); public gridwithintermediaterowscomponent() { beanitemcontainer<row> container = new beanitemcontainer<>(row.class); grid grid = new grid(container); // show relevant columns, style 1 used change background grid.setcolumns("name", "amount"); // set style generator can draw "total" rows differently grid.setcellstylegenerator(row -> ((row) row.getitemid()).getrowtype()); // create dummy data display (int = 0; < random.nextint(10) + 1; i++) { container.addall(createitembatch(random.nextint(5) + 1)); } addcomponent(grid); } private list<row> createitembatch(int total) { list<row> rows = new arraylist<>(total + 1); // add batch of products string product = available_products[random.nextint(available_products.length)]; (int = 0; < total; i++) { rows.add(new productrow(product, random.nextint(100) + 1)); } // calculate , add "total row" rows.add(calculatetotal(rows)); return rows; } private row calculatetotal(list<row> rows) { return new totalrow(rows.stream().maptoint(row::getamount).sum()); } }
5) theme styles
@mixin mytheme { @include valo; // insert own theme rules here .v-grid-row > td.total-row { background-color: #c4e7b7; font-weight: bold; } }
6) result
Comments
Post a Comment