Enhanced Datatables in Salesforce

Presenting data in a tabular form is one of the most preferred ways of displaying information (everyone loves spreadsheets!). So it is not a surprise that it is a preferred option to display records in Salesforce lightning components. Salesforce provides a very versatile datatable lightning web component (LWC). The datatable LWC provides a lot of functionality to manage and show records. Below, we list down a few features that can be added to enhance the datatable LWC. We found these features very useful and have built into our own reusable component library.

A datatable will often contain more than a handful of records. In such cases, either infinite scrolling or pagination is required. Infinite scroll is supported by the LWC datatable component. Pagination can be added to simplify records traversal. Pagination can be implemented either completely on LWC side (if the # of records are likely to fit in a few pages) or on the Apex side (if you expect the table to potentially fetch thousands of records). 

Search & Filter
Any browsing activity of datatable records will require searching and filtering. Salesforce List View enables this functionality very well. Incorporating search and filter to the standard datatable component enhances the user experience. Searching is useful for text fields whereas filtering is useful for picklist fields. Consider the impact on pagination while customizing the datatable to incorporate search. LWC datatable allows creation of header actions and filtering for picklist fields can be added as a column action that shows a list of available values to filter on. 

Export as CSV/PDF
Exporting the data as a CSV is very useful for taking the data out for further analysis in Excel or other programs. Export can be set up as a datatable level action.

Delete & Other Bulk Actions
Datatable provides the ability to select rows using a checkbox. Various actions can be performed on the selected rows programmatically. Deleting the selected rows is a very commonly implemented action. Along with delete, one can configure any other context relevant actions that can be performed on the selected rows. These actions can be made available as buttons above datatable that can be clicked after selecting multiple rows.

Custom Datatype in Cell: Images & Embedded Components
Datatable displays data of various standard datatypes as per appropriate formatting. Datatable allows you to create a custom datatype to implement a custom cell, an image, or even a custom text or number display. Custom datatypes can be very useful in displaying a relevant image in a cell. Custom datatypes can also be used to embed another LWC component in a cell. This can be used to show information such as progress ring, progress bar in one of the cell. You can refer to this link for an example of using custom datatype to embed another component in a cell.

As you can see, the standard LWC datatable can be customized further in multiple ways to add a few frequently used features to it. We have chosen to make this enhanced datatable part of our component library and you can see it in action in our Account Management App.

Team Varasi