URL on a field on my lightning datatable Component used to be working. When I add a search function I get the error as
'Action failed: c:test_filterComponent$controller$doInit [component is not defined]'
My controller
({
doInit: function (cmp, event, helper) {
cmp.set('v.mycolumns', [
// {label: 'Trainee Name', fieldName: 'Trainee__c', type: 'text',initialWidth: 300, cellAttributes: {alignment: 'left'},sortable: true},
{label: 'Trainee Name', fieldName: 'linkName', type: 'url', typeAttributes: {label: { fieldName: 'Trainee__c' }, initialWidth: 300,sortable: true}},
{label: 'Field', fieldName: 'Workplace__c', type: 'text',initialWidth: 300, cellAttributes: {alignment: 'left'},sortable: true},
{label: 'Department', fieldName: 'NZ_Ski_Dept_2021__c', type: 'text', initialWidth: 300, cellAttributes: {alignment: 'left'}, sortable: true},
{label: 'Online', fieldName: 'NZSki_Induction_2021_Online_Mod_Format__c', type: 'text', cellAttributes: {alignment: 'center'},initialWidth: 100, sortable: true},
{label: 'Standards', fieldName: 'NZSki_Induction_Mod_Format__c', type: 'text', cellAttributes: {alignment: 'center'}, initialWidth: 100, sortable: true}
]);
var action = component.get("c.getTPlans");
action.setCallback(this, function(response){
var records =response.getReturnValue();
records.forEach(function(record){
// record['linkName'] = 'https://skillsactiveaotearoa.force.com/nzski3/s/detail/'+ record.TraineeRef__c;
record['linkName'] = 'https://preprod-skillsactiveaotearoa.cs197.force.com/nzski3/s/detail/'+ record.TraineeRef__c;
});
component.set("v.mydata", records);
});
$A.enqueueAction(action);
var actionFilter = {"field":cmp.get("v.field"),"dept":cmp.get("v.dept")};
helper.getData(cmp, actionFilter);
},
doSearch:function(cmp, event, helper){
var actionFilter = {"field":cmp.get("v.field"),"dept":cmp.get("v.dept")};
helper.getData(cmp, actionFilter);
},
updateColumnSorting: function (cmp, event, helper) {
var fieldName = event.getParam('fieldName');
var sortDirection = event.getParam('sortDirection');
// assign the latest attribute with the sorted column fieldName and sorted direction
cmp.set("v.sortedBy", fieldName);
cmp.set("v.sortedDirection", sortDirection);
helper.sortData(cmp, fieldName, sortDirection);
}
})
Helper
({
getData : function(cmp, actionFilter) {
var action = cmp.get('c.getTPlans');
action.setParams(actionFilter)
action.setCallback(this, $A.getCallback(function (response) {
var state = response.getState();
if (state === "SUCCESS") {
cmp.set('v.mydata', response.getReturnValue());
} else if (state === "ERROR") {
var errors = response.getError();
console.error(errors);
}
}));
$A.enqueueAction(action);
},
sortData: function (cmp, fieldName, sortDirection) {
var data = cmp.get("v.mydata");
var reverse = sortDirection !== 'asc';
//sorts the rows based on the column header that's clicked
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]};
//checks if the two rows should switch places
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
}
})
Can someone help to find where I wrong