0

Sorting is working with any data type but url. Columns with url data type sorts according to underlying ID of the url. But I want the sorting display label. eg. I have a contact name with url link it does not sort according to the last name but Id of te url. This is my code:

HELPER: ({ sortData: function (cmp, fieldName, sortDirection) { var data = cmp.get("v.enrolmentRows"); var reverse = sortDirection !== 'asc'; //sorts the rows based on the column header that's clicked data.sort(this.sortBy(fieldName, reverse)) cmp.set("v.enrolmentRows", 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)?key(a):'', b = key(b)?key(b):'', reverse * ((a > b) - (b > a));

    }
}

})

Part of CONTROLLER: doInit: function(component, event, helper) {

    component.set('v.mycolumns', [
        {label: 'Trainee', fieldName: 'linkName', type: 'url',
         typeAttributes: {label: { fieldName: 'Trainee_Name__c'}}, initialWidth: 150, cellAttributes: {alignment: 'left'}},  
        {label: 'Progress %', fieldName: 'Progress__c', type: 'number', initialWidth: 115, cellAttributes: {alignment: 'center'}, sortable: true},
        {label: 'Status', fieldName: 'Moodle_Enrolment_Status__c', type: 'text',initialWidth: 125, cellAttributes:{alignment: 'left'}, sortable: true},
        {label: 'To be Graded', fieldName: 'Waiting_for_Grading__c', type: 'number',  initialWidth: 115, cellAttributes: {alignment: 'center'}, sortable: true},
        {label: 'Assessor', fieldName: 'linkNameAss', type: 'url', 
         typeAttributes: {label: { fieldName: 'Assessor_Name__c' }},initialWidth: 150, cellAttributes: {alignment: 'left'}, sortable: true},
        {label: 'Last Access', fieldName: 'Last_Accessed__c', type: 'date',initialWidth: 125, sortable: true},
        {label: 'LSA', fieldName: 'LSA_Name__c', type: 'text',initialWidth: 125, cellAttributes:{alignment: 'left'}, sortable: true}
    ]);
2

I dont know if you ever got an answer for this Query but i managed to get round this by putting an If statement in to check for the URL columns fieldname and if it matches replace the field name with the data for the Label Field

HELPER: ({ sortData: function (cmp, fieldName, sortDirection) { 
var data = cmp.get("v.enrolmentRows"); 
var reverse = sortDirection !== 'asc'; 
//sorts the rows based on the column header that's clicked 
if(fieldName === 'URLFieldName')
{
  fieldName = 'LabelFieldName';
}
data.sort(this.sortBy(fieldName, reverse)) cmp.set("v.enrolmentRows", data);
},
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.