You need to sign in to do that
Don't have an account?
shalini sharma 24
sorting in lightning dataTable
Hi ,
I am doing sorting at the client side in helper class in lightning datatable using the below code. However, I am receiving null values in few columns and that is impacting the sorting of my data. How can I handle the null values to show at the last in the sorted table?
sortData: function (cmp, fieldName, sortDirection) {
var data = cmp.get("v.mydata");
var reverse = sortDirection !== 'asc';
data.sort(this.sortBy(fieldName, reverse))
cmp.set("v.mydata", data);
},
sortBy: function (field, reverse, primer) {
var key = primer ?
function(x) {return primer(x[field])} :
function(x) {return x[field]};
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
},
I am doing sorting at the client side in helper class in lightning datatable using the below code. However, I am receiving null values in few columns and that is impacting the sorting of my data. How can I handle the null values to show at the last in the sorted table?
sortData: function (cmp, fieldName, sortDirection) {
var data = cmp.get("v.mydata");
var reverse = sortDirection !== 'asc';
data.sort(this.sortBy(fieldName, reverse))
cmp.set("v.mydata", data);
},
sortBy: function (field, reverse, primer) {
var key = primer ?
function(x) {return primer(x[field])} :
function(x) {return x[field]};
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
},
You have to make some changes in sortBy action as given below
Regards
Ashif
All Answers
You have to make some changes in sortBy action as given below
Regards
Ashif
http://www.infallibletechie.com/2018/03/lighting-data-table-sorting-example.html
It should work. Check the attributes used and check whether they are initialized.
It would be great if you can share the code for the above mentioned scenarios.