Skip to content

Instantly share code, notes, and snippets.

@svierk
Last active January 27, 2024 10:55
Show Gist options
  • Save svierk/ce6d65325187ba3f59ffbcee9480b9d4 to your computer and use it in GitHub Desktop.
Save svierk/ce6d65325187ba3f59ffbcee9480b9d4 to your computer and use it in GitHub Desktop.
JS Code for Content Document Table LWC | Columns & Data
export default class ContentDocumentTable extends NavigationMixin(LightningElement) {
@api recordId = null;
@api library = 'Documents';
@api folder = null;
@api showCard = false;
@api cardIcon = 'standard:file';
@api cardTitle = 'Document Table';
@api showDownloadAction = false;
@api showViewAction = false;
@api showDeleteAction = false;
@track columns = COLUMNS;
@track documents = [];
@track wiredRecords = [];
isLoading = true;
@wire(getDocuments, {
library: '$library',
folder: '$folder',
recordId: '$recordId'
})
wiredGetRecords(result) {
this.wiredRecords = result;
if (result.data) {
const documents = JSON.parse(result.data);
if (Array.isArray(documents)) {
documents.forEach((element) => {
element.icon = ICONS[element.FileExtension] ? ICONS[element.FileExtension] : ICONS.default;
element.preview = {
id: element.Id,
name: element.Title
};
if (element.ContentSize) element.ContentSize = this.formatSize(element.ContentSize);
});
this.documents = JSON.parse(JSON.stringify(documents));
}
this.isLoading = false;
}
}
connectedCallback() {
this.columns = COLUMNS.slice();
this.addRowActions();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment