DataGridView

public class DataGridView extends LinearLayout

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

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.

The minimal code needed to use DataGridView is as follows:

dataGridView = (DataGridView) findViewById(R.id.data_view);
dataGridView.setPageSize(3);
List 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 gridview looks like this

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

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

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

Fields

LEFT

public static final boolean LEFT

data

protected List<Map> data

Constructors

DataGridView

public DataGridView(Context context)

DataGridView

public DataGridView(Context context, AttributeSet attrs)

DataGridView

public DataGridView(Context context, AttributeSet attrs, int defStyleAttr)

Methods

addColumn

public void addColumn(BaseColumn col, boolean position)

Add extra columns to the dataview

Parameters:
  • col
  • position – true to add column at the beginning, false to add to the right

addToolbarView

public void addToolbarView(View view)

getColumns

public Map<String, ColumnInterface> getColumns()

Returns of columns to use on this grid.

Returns:grid columns.

getContentLayout

public LinearLayout getContentLayout()

getCurrentPageString

protected String getCurrentPageString()

getDataListener

protected DataListener getDataListener()

getFooterLayout

protected LinearLayout getFooterLayout()

getNextPageBtn

protected Button getNextPageBtn()

isStripped

public void isStripped(boolean isStripped)

makeDataRows

protected void makeDataRows()

makeFooterRow

protected void makeFooterRow()

makeHeaderRow

protected void makeHeaderRow()

makeToolbarRow

protected void makeToolbarRow()

setColumns

public void setColumns(Map attributesLabel)

Determine how and which columns of your data will be displayed by passing them here.

This overrides the default implementation of using all the columns in you data.

this method accepts a map in the following form {“gender}

Parameters:
  • attributesLabel – a map

setData

public void setData(List<Map> data)

You can populate the datagrid using list of map data. This data will be paginated based on the page size set

Parameters:
  • data – data to display.

setHeaderColor

public void setHeaderColor(int headerColor)

setPageSize

public void setPageSize(int pageSize)

setPaginator

public void setPaginator(PaginatorInterface paginator, LazyResolver lazyResolver)

setQuery

public void setQuery(SQLiteDatabase database, String sql, String[] params)

You can populate the datagrid using a query. THe data grid will fetch data in a paginated manner base on the page size set.

dataGridView = (DataGridView) findViewById(R.id.content_dsp);
dataGridView.setPageSize(3);
dataGridView.setQuery(SqlHelper.getInstance(this).getReadableDatabase(),
                                 "select * from coffees", new String[]{});
Parameters:
  • database – a SQLiteDatabase to use
  • sql – querys to fetch data
  • params – binding params to the query

setStripColor

public void setStripColor(int stripColor)