I have used lwc data table and have set columns as below.
const columns = [
{label: 'Name', fieldName: 'Name', type: 'text', sortable: true},
{label: 'Active', fieldName: 'active', type: 'boolean', sortable: true}
];
then over a sort function I am getting the fieldName and tryoing to sort.
if(typeof fieldname === 'string'){
data.sort((a,b) => {
let valueA = key(a) ? key(a).toLowerCase() : '';
let valueB = key(b) ? key(b).toLowerCase() : '';
return reverse * ((valueA > valueB) - (valueB > valueA));
});
}else{
data.sort(function(a,b){
var a = key(a) ? key(a) : '';
var b = key(b) ? key(b) : '';
return reverse * ((a>b) - (b>a));
});
}
"if(typeof fieldname === 'string')
" is always returning data type as string and not returning the Active field as boolean.
Basically I am trying to implement sort function where I am trying to sort text and checkbox values.
fieldName !== fieldname