You need to sign in to do that
Don't have an account?
Mohita Kalra
How can I set default sorted direction in lightning datatable?
I have a datatable which has column of type date. I want to set the default sorting order of the column. That means it should not allow the user to sort but date should be in order of latest date first. Is that possible ?
Have you tried sortDirection attribute you can use this attribute to specify sorting direction Here is the sample code
updateColumnSorting(event) {
var fieldName = event.detail.fieldName;
var sortDirection = event.detail.sortDirection;
// assign the latest attribute with the sorted column fieldName and sorted direction
this.sortedBy = fieldName;
this.sortedDirection = sortDirection;
this.data = this.sortData(fieldName, sortDirection);
}
For your reference, you can check this blog too,
https://developer.salesforce.com/forums/?id=9060G0000005rnlQAA
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks.