JS Noob here. I am currently following lwc datatable documentation to create a datatable with actions. The constructor has an argument as 'data' which I want to pass in getRowActions method.
The 'data' param is passed from child class.
How do I access 'data' param in getRowActions method? Also, When I try to access any instance variable in getRowAction using this.variableName, I get reference error.
import { LightningElement, track } from 'lwc';
const actions = [
{ label: 'Show details', name: 'show_details' },
{ label: 'Delete', name: 'delete' }
];
const columns = [
];
export default class DatatableExample extends from LightningElement {
@track data = [];
@track columns = [];
constructor(data) {
super();
this.columns = [
// Other column data here
{ type: 'action', typeAttributes: { rowActions: this.getRowActions } },
]
}
getRowActions(row, doneCallback) {
const actions = [];
if (row['isActive']) {
actions.push({
'label': 'Deactivate',
'iconName': 'utility:block_visitor',
'name': 'deactivate'
});
} else {
actions.push({
'label': 'Activate',
'iconName': 'utility:adduser',
'name': 'activate'
});
}
// simulate a trip to the server
setTimeout(() => {
doneCallback(actions);
}), 200);
}
}