DataGridView Documentation

DataGridView can be used to display a list or table of data records providing features like pagination.

../_images/gridview.png

Its takes a List of Maps that contains data and renders each row using a set of ColumnInterface presenting data in the form of a table.

Usage

The minimal code needed to use DataGridView is as follows

dataGridView = (DataGridView) findViewById(R.id.data_view);
dataGridView.setPageSize(3);
List<Map> data = "...";
dataGridView.setData(data);

Its also possible to override which columns are used in the grid and customize those columns as one wishes.

Assuming in the data provided to the DataGridView looks like this

[{"first_name":"jake", "age":"4"}, {"first_name":"joan", "age":"6"}, ]

Show specific columns

The earlier example will render both the firstname and age column on the grid we can tell the DataGridView to only render the firstname by setColumns(Map) <DataGridView.setColumns(Map) as shown below:

Map cols = new HashMap();
cols.put("first_name", new Column(this,"first_name","First Name"));
dataGridView.setColumns(cols);

Add columns

On top of columns that relate to the data prodided, with DataGridView you have the ability to addColumn(BaseColumn, boolean) e.g. action columns, serial columns or your own custom columns.

dataGridView.addColumn(new SerialColumn(this, "#"), DataGridView.LEFT);
dataGridView.addColumn(new EditActionColumn(this, "Edit"), DataGridView.RIGHT);
dataGridView.addColumn(new DeleteActionColumn(this, "Delete"), DataGridView.RIGHT);

Setting Data

The datagrid view supports two forms of setting data.

  • set a list of map data like we have been doing above using the setData() method.
  • set a list of map data like we have been doing above using the setQuery() method.

Columns

Learn more about columns Columns