Prepare Data"

From Documentation
(Created page with "{{ZKPivottableEssentialsPageHeader}} {{Template:UnderConstruction}} <!-- TODO --> =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content...")
 
Line 2: Line 2:
  
 
{{Template:UnderConstruction}}
 
{{Template:UnderConstruction}}
 +
 +
Pivottable takes a model for its data population. Analogous to ListModel for Grid component, the model interface we use for Pivottable is PivotModel.
 +
 +
However, unlike Grid or Listbox, due to the logic of pivot table, we cannot specify data as children components of a Pivottable, so you always need to prepare a PivotModel prior to using Pivottable.
 +
 +
==Construct a PivotModel==
 +
 +
TabularPivotModel is a standard implementation of PivotModel. It's constructor takes two <tt>List</tt>, for raw data and column labels.
 +
 +
<source lang="java">
 +
public TabularPivotModel(List<? extends List<?>> data, List<String> columns) { ... }
 +
</source>
 +
 +
<!-- TODO: live data -->
 +
 +
Here is a simple example of constructing a TabularPivotModel.
 +
 +
<source lang="java">
 +
public static TabularPivotModel getModel() {
 +
return new TabularPivotModel(getData(), getColumns());
 +
}
 +
 +
// raw data
 +
public static List<List<Object>> getData() {
 +
Object[][] objs = new Object[][] {
 +
{ "Carlene Valone", "Tameka Meserve",    "ATB Air", "AT15",  "Berlin",    "Paris",    186.6, 545  },
 +
{ "Antonio Mattos", "Sharon Roundy",    "Jasper",  "JS1",  "Frankfurt",  "Berlin",    139.5, 262  },
 +
{ "Russell Testa",  "Carl Whitmore",    "Epsilon", "EP2",  "Dublin",    "London",    108.0, 287  },
 +
{ "Antonio Mattos", "Velma Sutherland",  "Epsilon", "EP5",  "Berlin",    "London",    133.5, 578  },
 +
{ "Carlene Valone", "Cora Million",      "Jasper",  "JS30",  "Paris",      "Frankfurt", 175.4, 297  },
 +
{ "Richard Hung",  "Candace Marek",    "DTB Air", "BK201", "Manchester", "Paris",    168.5, 376  },
 +
{ "Antonio Mattos", "Albert Briseno",    "Fujito",  "FJ1",  "Berlin",    "Osaka",    886.9, 5486 },
 +
{ "Russell Testa",  "Louise Knutson",    "HST Air", "HT6",  "Prague",    "London",    240.6, 643  },
 +
{ "Antonio Mattos", "Jessica Lunsford",  "Jasper",  "JS9",  "Munich",    "Lisbon",    431.6, 1222 },
 +
{ "Becky Schafer",  "Lula Lundberg",    "Jasper",  "JS1",  "Frankfurt",  "Berlin",    160.5, 262  }
 +
};
 +
 +
List<List<Object>> list = new ArrayList<List<Object>>();
 +
for(Object[] a : objs)
 +
list.add(Arrays.asList(a));
 +
return list;
 +
}
 +
 +
// column labels
 +
public static List<String> getColumns() {
 +
return Arrays.asList(new String[]{
 +
"Agent", "Customer", "Airline", "Flight", "Origin", "Destination", "Price", "Mileage"
 +
});
 +
}
 +
 +
</source>
 +
 +
<!-- TODO: how to generate data from .csv -->
  
 
<!-- TODO -->
 
<!-- TODO -->
  
=Version History=
+
==Version History==
 
{{LastUpdated}}
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
{| border='1px' | width="100%"

Revision as of 03:04, 28 March 2011


WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

Pivottable takes a model for its data population. Analogous to ListModel for Grid component, the model interface we use for Pivottable is PivotModel.

However, unlike Grid or Listbox, due to the logic of pivot table, we cannot specify data as children components of a Pivottable, so you always need to prepare a PivotModel prior to using Pivottable.

Construct a PivotModel

TabularPivotModel is a standard implementation of PivotModel. It's constructor takes two List, for raw data and column labels.

public TabularPivotModel(List<? extends List<?>> data, List<String> columns) { ... }


Here is a simple example of constructing a TabularPivotModel.

	public static TabularPivotModel getModel() {
		return new TabularPivotModel(getData(), getColumns());
	}
	
	// raw data
	public static List<List<Object>> getData() {
		Object[][] objs = new Object[][] {
				{ "Carlene Valone", "Tameka Meserve",    "ATB Air", "AT15",  "Berlin",     "Paris",     186.6, 545  },
				{ "Antonio Mattos", "Sharon Roundy",     "Jasper",  "JS1",   "Frankfurt",  "Berlin",    139.5, 262  },
				{ "Russell Testa",  "Carl Whitmore",     "Epsilon", "EP2",   "Dublin",     "London",    108.0, 287  },
				{ "Antonio Mattos", "Velma Sutherland",  "Epsilon", "EP5",   "Berlin",     "London",    133.5, 578  },
				{ "Carlene Valone", "Cora Million",      "Jasper",  "JS30",  "Paris",      "Frankfurt", 175.4, 297  },
				{ "Richard Hung",   "Candace Marek",     "DTB Air", "BK201", "Manchester", "Paris",     168.5, 376  },
				{ "Antonio Mattos", "Albert Briseno",    "Fujito",  "FJ1",   "Berlin",     "Osaka",     886.9, 5486 },
				{ "Russell Testa",  "Louise Knutson",    "HST Air", "HT6",   "Prague",     "London",    240.6, 643  },
				{ "Antonio Mattos", "Jessica Lunsford",  "Jasper",  "JS9",   "Munich",     "Lisbon",    431.6, 1222 },
				{ "Becky Schafer",  "Lula Lundberg",     "Jasper",  "JS1",   "Frankfurt",  "Berlin",    160.5, 262  }
		};
		
		List<List<Object>> list = new ArrayList<List<Object>>();
		for(Object[] a : objs)
			list.add(Arrays.asList(a));
		return list;
	}
	
	// column labels
	public static List<String> getColumns() {
		return Arrays.asList(new String[]{
				"Agent", "Customer", "Airline", "Flight", "Origin", "Destination", "Price", "Mileage"
		});
	}


Version History

Last Update : 2011/03/28


Version Date Content
     



Last Update : 2011/03/28

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.