Salesforce (LWC)
This document shows how to get this Slickgrid bundle working with Salesforce LWC (Lighning Web Component).
Step 1. install dependencies (static resources) one time setup in your org
The first thing you will need to do is to add the slickgrid bundle zip file as a new static resource, you can see the name below that we used in our Salesforce org (you can name it differently). The resource named Sf_SlickGrid comes from the zip file that gets created every time a new dist build is updated, the zip file can be downloaded here.
static resource files
Click on the zip link and then click the Download button on the top right to download it locally and finally upload it to your org.
Sf_SlickGrid
the file name is slickgrid-vanilla-bundle.zip and we named our static resource as Sf_SlickGrid but it could be any name really
Step 2. load Slickgrid
Please note that the project has TypeScript enums which Salesforce doesn't support by default, so to make them work, we moved them into a separate namespace under
Slicker.Enums(or simplyEnumsif you follow 2nd approach below). Also please note that fieldtypecan be simplified by defining them as string, for exampletype: 'number'(seeFieldTypeenum for all available types)
Option 2.2 to create a separate slickgrid helper is recommended
2.1 First Approach
Create the Static Resource required by Slickgrid-Universal as shown below (you can choose a different static resource name).
View
<template>
<!-- show a spinner -->
<div if:false={isLoaded} class="slds-is-relative">
<lightning-spinner alternative-text="Loading...">
</lightning-spinner>
</div>
<!-- slickGrid container-->
<div class="grid-container slds-p-horizontal">
<div class="user-grid"></div>
</div>
</template>In the same file, load the external file with connectedCallback and get your data through a @wire method. Technically the @wire method will be processed before the connectedCallback and so you can assume that when calling the initializeGrid method we will already have the dataset ready.
Notice below that in the gridOptions, there is a flag useSalesforceDefaultGridOptions that was added specifically for Salesforce project, it will internally use these global salesforce grid options for Salesforce (these options are merged with the following default global grid options).
Component
Note loading of static files could be handled by an external helper component (also see section 2.2 below, which is our recommended approach)
2.2 Second Approach for loading Static Resources (Recommended Approach)
NOTE: in our implementation, we moved all the common css/script imports into a slickGridHelper LWC component, this allowed us to have much simpler imports in our external components (see next paragraph below).
and finally the setup of Slickgrid becomes a lot more simplified in our external component (the other advantage is that all Wikis are written with this approach, that is without the Slicker namespace and it is closer to what we could do with TypeScript since all Wikis are actually written with TypeScript code)
Last updated