Salman
09/06/2023, 4:32 PM// code to translate
const [rowSelection, setRowSelection] = useState({});
<MaterialReactTable
getRowId={(row) => row.userId}
onRowSelectionChange={setRowSelection}
state={{ rowSelection }}
// below is what I have done and it’s not working, I think I am not declaring state and oonSelectionChange prop correctly as per Material React Table/>
@JsName("default")
external val _MaterialReactTable_: ComponentType<MaterialReactTableProps>
external interface MaterialReactTableProps:PropsWithSx {
var enableRowSelection: Boolean
var getRowId: ((originalRow: dynamic) -> dynamic)
var state: dynamic
var onRowSelectionChange: StateSetter<dynamic>
var onSelectionChange: ((evt: dynamic, rowData: dynamic) -> Unit)
}
_MaterialReactTable_ *{*
enableRowSelection = true
getRowId = *{* originalRow *->*
originalRow._*facilityId*_
}
state = selectedFacilities
onRowSelectionChange = selectedFacilitiesStateSetter
}
Artem Kobzar
09/07/2023, 11:17 AMvar myState by useState(44)
Salman
09/08/2023, 9:39 AMArtem Kobzar
09/08/2023, 10:03 AMselectedFacilities
look like?
Did you realize that the provided state should be an object with the rowSelection
field:
state = js("{ rowSelection: THE_VALUE_WITH_SELECTION }")
Salman
09/08/2023, 10:13 AMconst [rowSelection, setRowSelection] = useState({});
_MaterialReactTable_ *{*
enableRowSelection = true
getRowId = *{* originalRow *->*
originalRow._*facilityId*_
}
state = rowSelection
onRowSelectionChange = setRowSelection
}
as per your suggestion this is how it looks like now
_MaterialReactTable_ *{*
columns = _facilitiesColumns_
data = if (formMode == FormMode._ADD_) selectedGroupFacilities else parentGroupFacilities
enableRowSelection = true
onRowSelectionChange = setRowSelection
state = _js_("{ rowSelection: $rowSelection}")
}
It’s giving me a compile time error stating -> Argument must be a string constant for rowSelection state.Salman
09/08/2023, 10:33 AMArtem Kobzar
09/08/2023, 10:57 AMstate={{ rowSelection }}
You have two curly brackets on each side.
First pair is needed for the data-binding
The second pair is an object literal with the ES2015 syntax: instead of { rowSelection: rowSelection }
you could write just { rowSelection }