Manipulation
Accessing Data
To access cell data, obtain a DataRecord first:
DataRecord rec = table.getRecord(5); // The numbering of records is zero-based, so this will return 6th record
DataRecord rec = table.rec(); // This returns first record (with zero index)Now you can use methods that return proper value types to get cell values:
String s1 = rec.getString("firstField");
Boolean b1 = rec.getBoolean("secondField");
Integer i1 = rec.getInt("thirdField");Iterating Over Records
It's very often necessary to process all table's records. DataTable implements Iterable interface making this very easy:
for(DataRecord rec : table)
{
// Process the record
}![]() | For a |
Cloning Tables and Table Elements
The clone() method works differently for different subtypes of DataTable:
For a SimpleDataTable instance, it returns a deep copy of the instance. The type of the cloned instance is also SimpleDataTable.
For a ResultSetDataTable, FilteringDataTable or ProxyDataTable instance, it returns a SimpleDataTable that contains clones of records represented by the original table at the moment of cloning.
![]() | Note that the |
It is also possible to clone a record or the format of a table:
DataTable clonedTable = table.clone();
DataRecord clonedRecord = table.rec().clone();
TableFormat clonedFormat = table.getFormat().clone();Encoding and Decoding Tables
Data table encoding works differently for different subtypes of DataTable:
Any SimpleDataTable can be encoded into string and restored without data loss. A SimpleDataTable instance is encoded along with all its records.
To encode and decode a SimpleDataTable use the following code:
String encodedTable = table.encode(false); // false means don't use visible separators
DataTable restored = new SimpleDataTable(encodedTable);An instance of ResultSetDataTable or FilteringDataTable is encoded differently. Its records are not encoded and its id is encoded instead. This id allows the corresponding ProxyDataTable to locate the table on the Server and access required records.
ProxyDataTable instances cannot be encoded, as they do not require this operation.
Selecting Table Cells
To find the first record having value of Integer field field1 is equal to 123 use the below code:
DataRecord rec = table.select("field1", 123);If such record is not found, this method will return null.
Sorting Tables
Only instances of SimpleDataTable can be sorted. To sort a SimpleDataTable according to values of field field1, use this code:
table.sort("field1", true); // Ascending sort orderIf you need to sort a data table that is not of SimpleDataTable type, clone it first, which will make a SimpleDataTable copy of the original table, and then sort the cloned one.
Replicating Tables
It's often necessary to copy data between different data tables. First of all, a DataTable can be cloned (see above).
However, more advanced table replication operations are available as static methods of DataTableReplication class:
- A family of
copy()methods copy data from one table to another respecting key fields, read-only and non-replicated fields, minimum/maximum record counts, and more - A family of
copyRecord()methods replicate data from oneDataRecordto another respecting numerous options as well
Advanced Operations
Some advanced table operations, such as building tables from value lists or processing table bindings, are available in two open-source helper classes: DataTableBuilding and DataTableUtils.
Was this page helpful?

