I have a lightning-datatable (lwc) that has a number of columns that are sortable. I'm tracking the sort direction of each column with a separate variable.
The sorting works great, including sortDirection — except that the sort arrow on every column always points up — even if the actual sort is DESC.
I can't figure out how to change that. What is the value that datatable uses to determine which arrow to display?
Here's my markup:
<lightning-datatable
key-field="id"
data={responses}
columns={columns}
onsave={handleSave}
draft-values={draftValues}
onsort={handleSort}
sorted-by={sortedBy}
sorted-direction={sortedDirection}
onrowselection={handleRowSelected}
onrowaction={handleRowAction}
show-row-number-column
enable-infinite-loading
onloadmore={handleLoadMore}>
</lightning-datatable>
Best Answer
LWC (and Aura, Lightning, JavaScript, etc) is case sensitive. The allowed values are
asc
anddesc
. If you use the correct values, the arrows should appear in the correct direction.