Add and remove columns and rows.

Search for a command to run...

No comments yet. Be the first to comment.
PlutoGrid is a data grid. It is a Flutter package that allows you to easily edit large amounts of data with the keyboard. It can be used on any platform supported by Flutter.
I'm currently developing a grouping function of rows for version 5.2, which is the next version of PlutoGrid 5.1. [Done] Grouping of rows structured by columns Group multiple rows by column. (2 columns in the image) Dynamically change or ungroup gr...
A unique id can be set for PlutoMenuItem. PlutoMenuItem( id: 'unique_id', title: 'Menu 1', ) If PlutoMenuItem is created in build method, you should set a unique id for PlutoMenuItem.Otherwise, when PlutoMenuBar is rebuilt, incorrect actions suc...

The default ScrollBehavior.dragDevices of PlutoGrid is as follows.(dragDevices is a setting that allows scrolling by dragging to the set pointer type.) // In case of Mobile { PointerDeviceKind.touch, PointerDeviceKind.stylus, PointerDeviceKind....

Example code to add custom widget to PlutoMenuBar.

PlutoGrid has default shortcut keys set, and users can change or set shortcut keys. Shortcut Range The scope of the shortcut depends on the focus. PlutoGrid : In the state that TextField is not focused. You can set custom shortcut keys. TextField :...

PlutoLayout is a Flutter package for configuring layouts such as CMS or admin service.You can configure tab views or menus on the top, bottom, left, and right sides.It also supports keyboard shortcuts and allows you to toggle or resize the tab view. ...

After setting columns and rows in the constructor of PlutoGrid, how to add columns and rows during runtime and precautions are described.
PlutoGrid can set columns and rows in the constructor when creating the first grid as follows.
Note: Do not set columns and rows in the
buildmethod when setting columns and rows for the first time.
class DemoScreenState extends State<DemoScreen> {
final List<PlutoColumn> columns = [];
final List<PlutoRow> rows = [];
late PlutoGridStateManager stateManager;
@override
void initState() {
super.initState();
columns.addAll([
PlutoColumn(
title: 'name',
field: 'name_field',
type: PlutoColumnType.text(),
),
PlutoColumn(
title: 'age',
field: 'age_field',
type: PlutoColumnType.number(),
),
]);
rows.addAll([
PlutoRow(cells: {
'name_field': PlutoCell(value: 'Mike.'),
'age_field': PlutoCell(value: 20),
}),
PlutoRow(cells: {
'name_field': PlutoCell(value: 'John.'),
'age_field': PlutoCell(value: 21),
}),
]);
}
@override
Widget build(BuildContext context) {
// Do not add columns or rows here.
return Scaffold(
body: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
),
),
);
}
}
After columns and rows are set in the PlutoGrid constructor, to add or delete columns or rows, you have to do it through PlutoGridStateManager.
PlutoGridStateManager can be delivered through onLoaded callback function when PlutoGrid is created.
late final PlutoGridStateManager stateManager;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (event) => stateManager = event.stateManager,
),
),
);
}
Through the received PlutoGridStateManager, columns or rows can be added when a callback function such as onTap or stream.listen of the button is called.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
TextButton(
onPressed: () {
// Be careful not to duplicate field names when adding columns.
final int lastIndex = stateManager.refColumns.originalList.length;
stateManager.insertColumns(0, [
PlutoColumn(
title: 'new column $lastIndex',
field: 'new_field_$lastIndex',
type: PlutoColumnType.text(),
)
]);
},
child: const Text('Add column'),
),
Expanded(
child: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (event) => stateManager = event.stateManager,
),
),
),
],
),
);
}
The methods related to adding and removing columns and rows of PlutoGridStateManager are as follows.
// Add `columns` in place of `columnIdx`.
void insertColumns(int columnIdx, List<PlutoColumn> columns);
// Remove all `columns`.
void removeColumns(List<PlutoColumn> columns);
// Add `rows` in place of `rowIdx`.
void insertRows(
int rowIdx,
List<PlutoRow> rows, {
bool notify = true,
});
// Add new rows of length `count` before the first row.
void prependNewRows({
int count = 1,
});
// Add `rows` to the beginning of the first row.
void prependRows(List<PlutoRow> rows);
// Add new rows of length `count` after the last row.
void appendNewRows({
int count = 1,
});
// Add `rows` after the last row.
void appendRows(List<PlutoRow> rows);
// Remove the currently focused row.
void removeCurrentRow();
// Remove `rows` Remove all.
void removeRows(List<PlutoRow> rows);
// Remove all rows.
void removeAllRows({bool notify = true});
If the number of rows to be added at once is large, the UI may freeze due to the load on the CPU operation. In this case, the CPU operation can be processed asynchronously.
Below is a link to a demo page that works on the web. You can also check the example source code by tapping the Source button on the demo page.