Problem

How do I use the class WebDataSet


Solution

The class dataweb.util.treeset.WebDataSet is a tabular structure (row/column). To create the structure we must first define all the columns:

dataweb.util.treeset.WebDataSet wds = new dataweb.util.treeset.WebDataSet();
dataweb.util.treeset.WebDataSetSchema schema = wds.getSchema();
schema.addColumn("Col1", dataweb.util.treeset.WebDataSet.DATATYPE_CHAR, 50, 0);
schema.addColumn("Col2", dataweb.util.treeset.WebDataSet.DATATYPE_NUMERIC, 10, 2);
schema.addColumn("Col3", dataweb.util.treeset.WebDataSet.DATATYPE_DATETIME, 0, 0);
schema.addColumn("Col4", dataweb.util.treeset.WebDataSet.DATATYPE_BOOLEAN, 0, 0);

Then load the rows:

//Add row 1
int r=0;
wds.addRow();
wds.setValue(r, "Col1", "Val1");
wds.setValue(r, "Col2", 12.4);
wds.setValue(r, "Col3", dataweb.util.DateTimeUtil.getDate());
wds.setValue(r, "Col4", false);

//Add row 2
r++;
wds.addRow();
wds.setValue(r, "Col1", "Val2");
wds.setValue(r, "Col2", 12.4);
wds.setValue(r, "Col3", dataweb.util.DateTimeUtil.getDate(2010, 12, 27));
wds.setValue(r, "Col4", true);

Once loaded structure to read the values we use:

var val = wds.getValue(1, "Col3");

Other useful methods are:

getRowCount(); //indicates the number of records.
clear(); //Remove all rows;
applyFilter(String condition, String order); //Apply a filter and a sort
newFilteredWebDataSet(String filter, String sort); //Returns a new structure filtered and sorted (pointing to the same data)

Published in Mon, 27 December 2010 14:38