Skip to content

DataGridView is an Android library for displaying tabular data consisting of rows and columns.

License

Notifications You must be signed in to change notification settings

jkas-dbt/DataGridView

Repository files navigation

DataGridView

Screenshots

  • basic style without color pattern

GeneralAppearance

  • With color pattern and with vertical diviser only

GeneralAppearance

  • With color pattern and with horizontal diviser only

GeneralAppearance



Required

Integrate the DataGridVlew module into your project



Usage

include the namespace in your xml layout file :

xmlns:app="http://schemas.android.com/apk/res-auto"



DataGridVlew xml code

<jkas.datagridview.DataGridView
    android:id="@+id/data_grid_view"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    app:diviserSize="2dp"
    app:diviserColor="@color/backgroundColorHeader"
    app:diviserHeaderColor="@android:color/transparent"
    app:columnCount="5"
    app:columnHeaderTextColor="@color/textColorHeader"
    app:columnHeaderBackgroundColor="@color/backgroundColorHeader"
    app:columnHeaderHeight="43dp"
    app:showVerticalSeparator="true"
    app:showHorizontalSeparator="true"
    app:rowHeight="30dp"
    app:rowTextColor="@color/textColorRow"
    app:rowBackgroundColor="@color/backgroundColorRow" />



Implementation

  • To add data to the grid, you need to create an object of type Row from the DataGridView. from this new object created (Row), you would add new cells that will represent the data of the column. the object Cell can only be created from the line (object) Row that was created (rowObject.newCell())

java

DataGridView dataGV = binding.dataGridView; // get the DataGridVlew view via findViewById or DataBinding
Row row = dataGV.newRow(); // create the new row from the DataGridVlew.
// adding Cell in Row object
row.addCell(row.newCell().setTextContent("data cell 1"));
row.addCell(row.newCell().setTextContent("data cell 2"));
row.addCell(row.newCell().setTextContent("data cell 3"));
row.addCell(row.newCell().setTextContent("data cell 4"));
row.addCell(row.newCell().setTextContent("data cell 5"));

// adding Row line in DataGridVlew.
dataGV.addRow(row);

kotlin

val dataGV = binding.dataGridView //get the DataGridVlew view via findViewById or DataBinding.
val row = dataGV.newRow() // creating the record row (Row)
row.addCell(row.newCell().setTextContent("data cell 1"))
row.addCell(row.newCell().setTextContent("data cell 2"))
row.addCell(row.newCell().setTextContent("data cell 3"))
row.addCell(row.newCell().setTextContent("data cell 4"))
row.addCell(row.newCell().setTextContent("data cell 5"))

// adding Row line in DataGridVlew.
dataGV.addRow(row)



  • By default for all Cells, the default generated view will be the TextView. you can also customize your own views which are embedded in the Cells.

java

View myCustomView = ...; // The view you prefer to use instead of the one that will be created by default.
Row row = dataGV.newRow();
Row.Cell cell = row.newCell();
cell.setView(myCustomView);
row.addCell(cell);

kotlin

val myCustomView = ... // The view you prefer to use instead of the one that will be created by default.
val row = dataGV.newRow()
val cell = row.newCell()
cell.setView(myCustomView)
row.addCell(cell)



  • Creating the grid header always follows the same procedure which consists of creating a Row either via the newRow() method .

java

Row rowHeader = dataGV.newRow();
rowHeader.addCell(...); // adding all necessary cells.
// set or update header
dataGV.setHeader(rowHeader);

kotlin

val rowHeader = dataGV.newRow()
rowHeader.addCell(...) // adding all necessary cells.
// set or update header
dataGV.setHeader(rowHeader)



  • For setting up color patterns (as in screenshots) it's pretty simple. you just need to get the object keeps the default settings of the DataGridView and change its values DefaultSetting.

java

DataGridVlew.DefaultSetting setting = dataGV.getDefaultSetting(); // getting the DefaultSetting object.
setting.usePattern = true;

// for columns only.
setting.addColorInListColumn(Color.RED);
setting.addColorInListColumn(Color.GREEN);


// for rows only
setting.addColorInListRow(Color.RED);
setting.addColorInListRow(Color.GREEN);
//...

kotlin

val setting = dataGV.getDefaultSetting() // getting the DefaultSetting object.
setting.usePattern = true

// for columns only.
setting.addColorInListColumn(Color.RED)
setting.addColorInListColumn(Color.GREEN)


// for rows only
setting.addColorInListRow(Color.RED)
setting.addColorInListRow(Color.GREEN)
//...

If you want to use this multiple coloring of columns and/or rows, let the value of usePattern be true



Attributs

XML Attributs Code Method Description
app:diviserSize setDiviserSize(int size) the size of the column and row divider
app:diviserColor setDiviserColor(int color) The colors of the loaded data grid dividers
app:diviserHeaderColor setDiviserHeaderColor(int color) The color of the grid header dividers.
app:columnCount setColumnCount(int counter) The maximum number of columns allowed
app:columnHeaderTextColor setColumnHeaderTextColor(int color) The header text color
app:columnHeaderBackgroundColor setColumnHeaderBackgroundColor(int color) The header background color
app:columnHeaderHeight setColumnHeaderHeight(float dimen) the height size of the header
app:showVerticalSeparator showVerticalSeparator(boolean show) Show vertical divider
app:showHorizontalSeparator showHorizontalSeparator(boolean show) Show horizontal divider
app:rowHeight setRowHeight(float dimen) the height size of the row
app:rowTextColor setRowTextColor(int color) The row text color
app:rowBackgroundColor setRowBackgroundColor(int color) The row background color



Note

It is important to know this before loading data into the grid :

  • set columnCount before data loading, Otherwise an exception will be thrown.
  • the number of Cells added must be equal to columnCount otherwise an exception will be thrown if the number of Cells is greater than the limit columnCount.
  • if the number of Cells is less than columnCount, Cells will be added with default values (none) to fill the gaps.



Contact



Thanks to

About

DataGridView is an Android library for displaying tabular data consisting of rows and columns.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages