6 comments
Can we have a custom column? For Eg: I wanted to provide an icon with the title in the column. Is the renderer for that?
The renderer is a property that customizes the cell (row) of the corresponding column. Customizing column titles is possible with titleSpan .
/// You can customize the column title.
PlutoColumn(
titleSpan: const TextSpan(
children: [
WidgetSpan(
child: Text(
'* ',
style: TextStyle(color: Colors.red),
),
),
TextSpan(text: 'column title'),
],
),
);
Is there any event that is triggered when someone drag a column or hide a column?
I'm looking for the trigger so I can store and save the column order after dragging and save the visible columns.
You can listen for column move events with the PlutoGrid.onColumnsMoved callback. However, there is no event for hiding a column, adding a column, or deleting a column. I have attached the code below for these events.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';
import '../dummy_data/development.dart';
class EmptyScreen extends StatefulWidget {
static const routeName = 'empty';
const EmptyScreen({Key? key}) : super(key: key);
@override
_EmptyScreenState createState() => _EmptyScreenState();
}
class _EmptyScreenState extends State<EmptyScreen> {
late List<PlutoColumn> columns;
late List<PlutoRow> rows;
late PlutoGridStateManager stateManager;
late StreamSubscription<PlutoNotifierEvent> notifierEvent;
late final columnsNotifier = {
stateManager.moveColumn.hashCode,
stateManager.hideColumn.hashCode,
stateManager.hideColumns.hashCode,
stateManager.insertColumns.hashCode,
stateManager.removeColumns.hashCode,
stateManager.toggleFrozenColumn.hashCode,
};
@override
void initState() {
super.initState();
final dummyData = DummyData(10, 100);
columns = dummyData.columns;
rows = dummyData.rows;
}
@override
void dispose() {
notifierEvent.cancel();
super.dispose();
}
void _notifyListener(PlutoNotifierEvent event) {
if (event.notifier.firstWhere((e) => columnsNotifier.contains(e)) != -1) {
print('changed columns');
// Column currently displayed
print(stateManager.columns.length);
// All columns including hidden columns
print(stateManager.refColumns.originalList.length);
// fixed left column
print(stateManager.leftFrozenColumns.length);
// non-fixed column
print(stateManager.bodyColumns.length);
// fixed right column
print(stateManager.rightFrozenColumns.length);
// The index of the column according to the order in which the columns are displayed List<int>
// Assuming there is a column [0,1,2,3,4]
// If number 3 is fixed to the left, [3,0,1,2,4]
print(stateManager.columnIndexesByShowFrozen);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
notifierEvent = stateManager.streamNotifier.stream.listen(
_notifyListener,
);
},
),
),
),
);
}
}
Is it possible to create an action column having a button or link and then start an action using the data of this row? Every row should show the button or link. Thx jan
The framework is truly awesome. Is it possible to have vertical borders on ColumnGroups and NOT on Columns? This is to visually distinguish groups from each other better. It would also, possibly, be a good thing to have the ability to change the background colors on columns/column groups as well as on rows.