editable table
the editable table package allows you to create editable tables and spreadsheets with ease, either by providing initial row and column count to display an empty table or use it with predefined rows and column data sets.
features
- save edited rows
- save edited cell
- customize cell data
- add empty rows
- create empty tables
- customizable save button
- customize table headers
- zebra – stripe table
- style table border
getting started
in the pubspec.yaml
of your flutter project, add the following
dependency:
dependencies:
...
editable: "^1.1.1"
in your library add the following import:
import 'package:editable/editable.dart';
api
CREATE TABLE IF NOT EXISTS
to create a new table, use the editable()
widget class and provide the table data properties as follows:
column
: an array of objects example
example:list cols = [ {"title":'name', 'index': 1, 'key':'name'}, {"title":'date', 'index': 2, 'key':'date'}, {"title":'month', 'index': 3, 'key':'month'}, {"title":'status', 'index': 4, 'key':'status'}, ];
[title] is the column heading
[index] represents a unique id for each column of type [int]
[key] an identifyer preferably without space and special characters
rows
: an array of objects, where each object key represents a column [key],
example:list rows = [ {"name": 'james joe', "date":'23/09/2020',"month":'june',"status":'completed'}, {"date":'12/4/2020',"month":'march',"name": 'daniel paul', "status":'new'}, ];
each objects do not have to be positioned in same order as its column
rowcount
: interger value of number of rows to be generated: optional if row data is providedcolumncount
: interger value of number of columns to be generated: optional if column data is providedcolumnratio
: fraction of the screen width occupied by each column. this is usefull for shrinking and expanding table width
example:columnration: 0.2 //sets each column to occupy 20 percent of screen width
customization
bordercolor
: color of table borderborderwidth
: width of table borderstdpaddingleft
: table data cell padding lefttdpaddingtop
: table data cell padding toptdpaddingright
: table data cell padding right;tdpaddingbottom
: table data cell padding bottom;tdalignment
: aligns the table data ;tdstyle
: style the table data;thpaddingleft
: table header cell padding left;thpaddingtop
: table header cell padding top;thpaddingright
: table header cell padding right;thpaddingbottom
: table header cell padding bottom;trheight
: table row height, cannot be less than 40.0 ;thweight
: table headers fontweight;thsize
: table headers fontsize;showsaveicon
: toogles the save button, if [true] displays an icon to save rows,
adds an addition column to the rightsaveicon
: icon for to save row data, example:
dart saveicon : icons.add
saveiconcolor
: color for the save iconsaveiconsize
: size for the saveiconshowcreatebutton
: displays a button that adds a new row onpressedstripecolor1
: the first row alternate color, if stripe is set to truestripecolor2
: the second row alternate color, if stripe is set to true;zebrastripe
: enable zebra-striping, set to false by default
// if zebrastripe is enabled, you can style the colors [stripecolor1] and [stripecolor2]
createbuttonalign
: aligns the button for adding new rows;createbuttonicon
: icon displayed in the create new row button;createbuttoncolor
: color for the create new row button;createbuttonshape
: border shape of the create new row button
createbuttonshape: roundedrectangleborder( borderradius: borderradius.circular(8) )
createbuttonlabel
: label for the create new row button
save methods
onsubmitted
: [onsubmitted] callback is triggered when the enter button is tapped (for desktop users)
or when edit is complete(on mobile) on a table data cell
it returns a value of the edited cell dataonrowsaved
: [onrowsaved] callback is triggered when a [savebutton] is pressed.
returns only values if row is edited, otherwise returns a string [‘no edit’]
screenshots
editable table with data (zebrastripe)
empty spreadsheet (zebrastripe)
empty spreadsheet (no stripe)
table with save icon
roadmap
the following are immediate work in progress for the next version of the project:
- sortable column
- perform mathematical operations between columns (wip)
- search row data (wip)
- export table to different formats
contribution
i highly encourage the community to step forward and improve this
library further. you can fix any reported bug, propose or implement new
features, write tests, etc.
here is a quick list of things to remember
- check the open issues before creating a new one,
- help me in reducing the number of open issues by fixing any existing
bugs, - check the roadmap to see if you can help in implementing any new
feature, - you can contribute by writing unit and integration tests for this
library, - if you have any new idea that aligns with the goal of this library,
feel free to raise a feature request and discuss it.
Comments are closed.