Last active
October 4, 2023 17:24
-
-
Save k4zek4ge/95b937f027f3cc626e27ba9b66cf4dcf to your computer and use it in GitHub Desktop.
[pluto grid checked rows] #flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stateManager.rows | |
//You can access rows in List type. | |
//However, if they are filtered, you can only access them. | |
stateManager.refRows.originalList | |
//Same as rows, but you can access all rows regardless of filtering or not. | |
//Every row has a cells property and this is a map. | |
//The field value specified in the column can be accessed with the key. | |
//Suppose you have a field called user_id. | |
//If you need to get the user_id values of all rows into a List, you can do as follows. | |
var user_ids = stateManager.refRows.originalList.map((e) => e.cells['user_id'].value.toString()); | |
//If user_id is retrieved only from the currently displayed rows in the filtered state, it is as follows. | |
var user_ids = stateManager.rows.map((e) => e.cells['user_id'].value.toString()); | |
var user_ids = stateManager.refRows.map((e) => e.cells['user_id'].value.toString()); | |
//rows and refRows are the same. However, rows are just destructured. | |
//When creating a grid, register a callback function with addListener in the stateManager. | |
body: PlutoGrid( | |
columns: columns, | |
rows: rows, | |
onChanged: (PlutoGridOnChangedEvent event) { | |
print(event); | |
}, | |
onLoaded: (PlutoGridOnLoadedEvent event) { | |
event.stateManager.setSelectingMode(PlutoGridSelectingMode.row); | |
stateManager = event.stateManager; | |
stateManager.addListener(handleCheckedRow); | |
}, | |
// configuration: PlutoConfiguration.dark(), | |
), | |
//Access checked or unchecked rows with stateManager.checkedRows or stateManager.unCheckedRows property in callback function. | |
List<PlutoRow> checkedRows = []; | |
void handleCheckedRow() { | |
var currentCheckedRows = stateManager.checkedRows; | |
if (!listEquals(checkedRows, currentCheckedRows)) { | |
checkedRows = stateManager.checkedRows; | |
print('changed!'); | |
} else { | |
print('not changed!'); | |
} | |
} | |
//In the case of the selection column, values other than items are not changed. | |
//Currently, you can change the value in the following way. | |
stateManager.currentCell.value = ''; | |
stateManager.notifyListeners(); | |
//And changing the value is as follows. | |
// For force, the default is false. | |
// This is when the mode of the grid is select, | |
// only the row can be selected and the value cannot be modified. | |
// In this case, the value can be forcibly modified. | |
stateManager.changeCellValue(stateManager.currentCell.key, null, force: true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment