You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Results in search component can be clicked but do not lead to the result-object
Hello friends,
I build a search component which is working fine on an object named "Mediathek". I find results when I search through the component but the problem is, that by clicking on the results, I'm not lead to the record. Could you tell me what the reason in my code could be?
COMPONENT:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="MediathekSearchController">
<!-- handlers-->
<aura:handler name="init" value="{!this}" action="{!c.init}"/>
<!-- attributes -->
<aura:attribute name="showSearchResults" type="Boolean" default="false"/>
<aura:attribute name="searchKey" type="String"/>
<aura:attribute name="mediathekList" type="List" default="Mediathek[]"/>
<aura:attribute name="mediathekColumns" type="List"/>
<lightning:layout multipleRows="true">
<lightning:layoutItem padding="around-small" size="9">
<lightning:input name="searchKey" placeholder="Enter search key" value="{!v.searchKey}"/>
</lightning:layoutItem>
<lightning:layoutItem padding="around-small" size="3">
<lightning:button variant="brand" label="Search" title="Search" onclick="{!c.search}" class="customButton"/>
</lightning:layoutItem>
</lightning:layout>
<aura:if isTrue="{!v.showSearchResults}">
<lightning:layout multipleRows="true">
<lightning:layoutItem padding="around-small" size="12">
Mediathek
<lightning:datatable keyField="id"
data="{!v.mediathekList}"
columns="{!v.mediathekColumns}"
hideCheckboxColumn="true"/>
</lightning:layoutItem>
</lightning:layout>
</aura:if>
</aura:component>
CONTROLLER
({
init: function (component, event, helper){
component.set('v.mediathekColumns', [
{label: 'Mediathek Name', fieldName: 'Name', type: 'url',
typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
]);
},
search : function(component, event, helper) {
helper.getSearchResultsFromApex(component, event, helper);
component.set("v.showSearchResults",true);
}
})
HELPER
({
getSearchResultsFromApex : function(component, event, helper){
var action = component.get("c.getSearchResult");
action.setParams({ searchKey : component.get("v.searchKey") });
// Create a callback that is executed after
// the server-side action returns
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
result.forEach(function(result){
result.Name = '/'+result.Id;
});
// SOSL will always return the list in the order they were queried
component.set("v.mediathekList",result[0]);
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
}
})
STYLE
.THIS .customButton{
margin-top: 19px;
}
.cMediathekSuchleiste{
height: 50px;
background-color:#ffffff;
}
APEX CLASS
public class MediathekSearchController {
@AuraEnabled(cacheable=true)
public static List<List<sObject>> getSearchResult(String searchKey){
List<List<sObject>> searchResult = [FIND :searchKey
IN ALL FIELDS RETURNING
Mediathek__c (Id, Name)
];
return searchResult;
}
}
I build a search component which is working fine on an object named "Mediathek". I find results when I search through the component but the problem is, that by clicking on the results, I'm not lead to the record. Could you tell me what the reason in my code could be?
COMPONENT:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="MediathekSearchController">
<!-- handlers-->
<aura:handler name="init" value="{!this}" action="{!c.init}"/>
<!-- attributes -->
<aura:attribute name="showSearchResults" type="Boolean" default="false"/>
<aura:attribute name="searchKey" type="String"/>
<aura:attribute name="mediathekList" type="List" default="Mediathek[]"/>
<aura:attribute name="mediathekColumns" type="List"/>
<lightning:layout multipleRows="true">
<lightning:layoutItem padding="around-small" size="9">
<lightning:input name="searchKey" placeholder="Enter search key" value="{!v.searchKey}"/>
</lightning:layoutItem>
<lightning:layoutItem padding="around-small" size="3">
<lightning:button variant="brand" label="Search" title="Search" onclick="{!c.search}" class="customButton"/>
</lightning:layoutItem>
</lightning:layout>
<aura:if isTrue="{!v.showSearchResults}">
<lightning:layout multipleRows="true">
<lightning:layoutItem padding="around-small" size="12">
Mediathek
<lightning:datatable keyField="id"
data="{!v.mediathekList}"
columns="{!v.mediathekColumns}"
hideCheckboxColumn="true"/>
</lightning:layoutItem>
</lightning:layout>
</aura:if>
</aura:component>
CONTROLLER
({
init: function (component, event, helper){
component.set('v.mediathekColumns', [
{label: 'Mediathek Name', fieldName: 'Name', type: 'url',
typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
]);
},
search : function(component, event, helper) {
helper.getSearchResultsFromApex(component, event, helper);
component.set("v.showSearchResults",true);
}
})
HELPER
({
getSearchResultsFromApex : function(component, event, helper){
var action = component.get("c.getSearchResult");
action.setParams({ searchKey : component.get("v.searchKey") });
// Create a callback that is executed after
// the server-side action returns
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
result.forEach(function(result){
result.Name = '/'+result.Id;
});
// SOSL will always return the list in the order they were queried
component.set("v.mediathekList",result[0]);
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
}
})
STYLE
.THIS .customButton{
margin-top: 19px;
}
.cMediathekSuchleiste{
height: 50px;
background-color:#ffffff;
}
APEX CLASS
public class MediathekSearchController {
@AuraEnabled(cacheable=true)
public static List<List<sObject>> getSearchResult(String searchKey){
List<List<sObject>> searchResult = [FIND :searchKey
IN ALL FIELDS RETURNING
Mediathek__c (Id, Name)
];
return searchResult;
}
}
Does it show any error in the logs because of which the redirection might not be happening?
No I do not get no errors. I think, there schould be something changed in the code so the result-pages are connected to search component