Theme:
Description & Source Code

A grid can have merged headers to help better organize its content.
In this demo, a group of radio buttons is placed in the merged header to filter out food categories. At the bottom, a label at the right side of the footer indicates how many food items are selected.

<zk>
	<style src="/widgets/grid/header_and_footer/Style.css" />
	<grid apply="demo.grid.header_and_footer.FoodListController">
		<auxhead sclass="category-center">
			<auxheader label="Healthy Food List" colspan="6" rowspan="1" />
		</auxhead>
		<auxhead sclass="category-center">
			<auxheader label="Category Select" colspan="1" rowspan="1" />
			<auxheader colspan="5" rowspan="1">
				<radiogroup id="categorySelector">
					<hlayout>
						<radio label="All Food" checked="true" width="100px" />
						<radio label="Vegetables" width="100px" />
						<radio label="Seafood" width="100px" />
						<radio label="Fruits" width="100px" />
						<radio label="Poultry &amp; Lean Meats" width="100px" />
					</hlayout>
				</radiogroup>
			</auxheader>
		</auxhead>
		<columns>
			<column hflex="2">Category</column>
			<column hflex="2">Name</column>
			<column hflex="1">Top Nutrients</column>
			<column hflex="1">% of Daily</column>
			<column hflex="1">Calories</column>
			<column hflex="2">Quantity</column>
		</columns>
		<template name="model">
			<row>
				<label value="${each.category}"></label>
				<label value="${each.name}"></label>
				<label value="${each.topNutrients}"></label>
				<label value="${each.dailyPercent}"></label>
				<label value="${each.calories}"></label>
				<label value="${each.quantity}"></label>
			</row>
		</template>
		<foot>
			<footer span="6" id="footer_category" class="footer_right" />
		</foot>
	</grid>
</zk>
package demo.grid.header_and_footer;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.CheckEvent;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Footer;
import org.zkoss.zul.Grid;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Radio;

import demo.data.FoodData;
import demo.data.pojo.Food;

public class FoodListController extends SelectorComposer<Component> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5219591488010056129L;

	private Grid foolList;

	@Wire
	private Footer footer_category;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		foolList = (Grid) comp;
		foolList.setModel(new ListModelList<Food>(FoodData.getAllFoods()));
		footer_category.setLabel("A Total of " + FoodData.getAllFoods().size() + " Food Items");
	}

	@Listen("onCheck = #categorySelector")
	public void selectCategory(CheckEvent event) {
		String selectedCategory = ((Radio) event.getTarget()).getLabel();
		if (selectedCategory.equals("All Food")) {
			foolList.setModel(new ListModelList<Food>(FoodData.getAllFoods()));
		} else {
			foolList.setModel(new ListModelList<Food>(FoodData.getFoodsByCategory(selectedCategory)));
		}
		footer_category.setLabel("A Total of " + foolList.getRows().getChildren().size() + " Food Items");
	}
}
package demo.data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import demo.data.pojo.Food;
import demo.grid.data_filter.FoodFilter;

public class FoodData {

	private static List<Food> foods = new ArrayList<Food>();
	static {
		foods.add(new Food("Vegetables", "Asparagus", "Vitamin K", 115, 43, "1 cup - 92 grams"));
		foods.add(new Food("Vegetables", "Beets", "Folate", 33, 74, "1 cup - 170 grams"));
		foods.add(new Food("Vegetables", "Bell peppers", "Vitamin C", 291, 24, "1 cup - 92 grams"));
		foods.add(new Food("Vegetables", "Cauliflower", "Vitamin C", 92, 28, "1 cup - 124 grams"));
		foods.add(new Food("Vegetables", "Eggplant", "Dietary Fiber", 10, 27, "1 cup - 99 grams"));
		foods.add(new Food("Vegetables", "Onions", "Chromium", 21, 60, "1 cup - 160 grams"));
		foods.add(new Food("Vegetables", "Potatoes", "Vitamin C", 26, 132, "1 cup - 122 grams"));
		foods.add(new Food("Vegetables", "Spinach", "Vitamin K", 1110, 41, "1 cup - 180 grams"));
		foods.add(new Food("Vegetables", "Tomatoes", "Vitamin C", 57, 37, "1 cup - 180 grams"));
		foods.add(new Food("Seafood", "Salmon", "Tryptophan", 103, 261, "4 oz - 113.4 grams"));
		foods.add(new Food("Seafood", "Shrimp", "Tryptophan", 103, 112, "4 oz - 113.4 grams"));
		foods.add(new Food("Seafood", "Scallops", "Tryptophan", 81, 151, "4 oz - 113.4 grams"));
		foods.add(new Food("Seafood", "Cod", "Tryptophan", 90, 119, "4 oz - 113.4 grams"));
		foods.add(new Food("Fruits", "Apples", "Manganese", 33, 61, "1 cup - 160 grams"));
		foods.add(new Food("Fruits", "Cantaloupe", "Vitamin C", 112, 56, "1 cup - 160 grams"));
		foods.add(new Food("Fruits", "Grapes", "Manganese", 33, 61, "1 cup - 92 grams"));
		foods.add(new Food("Fruits", "Pineapple", "Manganese", 128, 75, "1 cup - 155 grams"));
		foods.add(new Food("Fruits", "Strawberries", "Vitamin C", 24, 48, "1 cup - 150 grams"));
		foods.add(new Food("Fruits", "Watermelon", "Vitamin C", 24, 48, "1 cup - 152 grams"));
		foods.add(new Food("Poultry & Lean Meats", "Beef, lean organic", "Tryptophan", 112, 240, "4 oz - 113.4 grams"));
		foods.add(new Food("Poultry & Lean Meats", "Lamb", "Tryptophan", 109, 229, "4 oz - 113.4 grams"));
		foods.add(new Food("Poultry & Lean Meats", "Chicken", "Tryptophan", 121, 223, "4 oz - 113.4 grams"));
		foods.add(new Food("Poultry & Lean Meats", "Venison ", "Protein", 69, 179, "4 oz - 113.4 grams"));
		foods.add(new Food("Grains", "Corn ", "Vatamin B1", 24, 177, "1 cup - 164 grams"));
		foods.add(new Food("Grains", "Oats ", "Manganese", 69, 147, "1 cup - 234 grams"));
		foods.add(new Food("Grains", "Barley ", "Dietary Fiber", 54, 270, "1 cup - 200 grams"));
	}

	public static List<Food> getAllFoods() {
		return foods;
	}
	public static Object[] getAllFoodsArray() {
		return foods.toArray();
	}

	// This Method only used in "Data Filter" Demo
	public static List<Food> getFilterFoods(FoodFilter foodFilter) {
		List<Food> somefoods = new ArrayList<Food>();
		for (Iterator<Food> i = foods.iterator(); i.hasNext();) {
			Food tmp = i.next();
			if (tmp.getCategory().toLowerCase().indexOf(foodFilter.getCategory()) >= 0 &&
				tmp.getName().toLowerCase().indexOf(foodFilter.getName()) >= 0 &&
				tmp.getTopNutrients().toLowerCase().indexOf(foodFilter.getNutrients()) >= 0) {
				somefoods.add(tmp);
			}
		}
		return somefoods;
	}

	// This Method only used in "Header and footer" Demo
	public static List<Food> getFoodsByCategory(String category) {
		List<Food> somefoods = new ArrayList<Food>();
		for (Iterator<Food> i = foods.iterator(); i.hasNext();) {
			Food tmp = i.next();
			if (tmp.getCategory().equals(category))
				somefoods.add(tmp);
		}
		return somefoods;
	}
}
.z-label,.z-radio {
	display: block;
}

tr.z-row td.z-row-inner {
	padding: 2px 5px;
}

.z-row-cnt,.z-column-cnt {
	text-align: center;
}

.category-center .z-auxheader-cnt {
	text-align: center;
}

.footer_right {
	text-align: right;
}