react-bootstrap-table2
react-bootstrap-table2 copied to clipboard
Add `Promise<void>` as a type for onSelect and onSelectAll functions to be able to use async-await.
I am using bootstrap-table-next made for typescript, and trying to implement the checkbox mode for the table rows as follows
const selectRow: SelectRowProps<any> = {
mode: "checkbox",
clickToSelect: false,
classes: "selection-row",
onSelect: async (row, isSelect, rowIndex, e) => {
if(isSelect){
//do something with the row data
//I want to call a method that returns a promise
const data = await returnSomeData(row.id)
//do something with the returned data
}
},
onSelectAll: async (isSelect, rows, e) => {
let cards: any[] = [];
if(isSelect){
rows.forEach((row, rowIndex) => {
//do something with the row data
//I want to call a method that returns a promise
const data = await returnSomeData(row.id)
//do something with the returned data
})
}
}
};
Currently async-await does not work for onSelect and onSelectAll and give the following errors if I add async before the function call as I have done in the above example:
- Type
Promise<void>is not assignable to typeboolean | void(onSelect) - Type
Promise<void>is not assignable to typevoid | number[](onSelectAll)
Could you please also add the Type Promise<void> for the 2 callback functions so we can also use async-await inside the callback functions
I am not sure if there's a reason why this feature isn't there at the moment, if there's a specific reason for not having this, please let me know.
The alternative solution I tried is to use when-then way of calling the async function but I am facing scope issues when it comes to multiple rows.
I would really appreciate it if this feature could be possible.