Skip to content

Instantly share code, notes, and snippets.

@Frelseren
Created May 22, 2022 16:57
Show Gist options
  • Save Frelseren/ae56a87f77654bea7542bf826ecae1be to your computer and use it in GitHub Desktop.
Save Frelseren/ae56a87f77654bea7542bf826ecae1be to your computer and use it in GitHub Desktop.
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import { subscribe } from 'lightning/empApi';
export default class CustomDataTable extends NavigationMixin(LightningElement) {
data = [
// data table data
];
columns = [
// other data table column definitions,
{
initialWidth: 120,
type: 'button',
typeAttributes: {
label: 'Create task',
name: 'create_task',
title: 'Create task',
variant: 'brand'
},
},
]
subscription = {};
CHANNEL_NAME = '/event/Refresh_Record__e';
_handleRefreshRecord(event) {
// business logic to refresh UI
}
handleRefreshRecord = _handleRefreshRecord.bind(this)
connectedCallback() {
subscribe(this.CHANNEL_NAME, -1, this.handleRefreshRecord).then(response => {
this.subscription = response;
});
}
handleRowAction(event) {
const { action, row } = event.detail;
const defaultFieldValues = encodeDefaultFieldValues({
WhatId: row.WhatId,
});
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'Task',
actionName: 'new',
},
state: {
defaultFieldValues,
navigationLocation: 'RELATED_LIST'
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment