function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonathan Wolff 7Jonathan Wolff 7 

Fix Component to show records on custom object with special field value

Hello, I want to build a datatable component that shows all files of the records in the custom object "Mediathek. for now I wanted to make a datatable that shows the records on Mediathek where Typ = 'Printmaterial'. Could you show me how to fix my component to achive it?
When saving I do get this error:
Failed to save PrintmaterialDatatableController.js: c.PrintmaterialDatatable: Failed to parse CONTROLLER for js://c.PrintmaterialDatatable: org.auraframework.util.json.JsonStreamReader$JsonStreamParseException: Expected ',' or '}', got FUNCTION_ARGS_END [25, 2]: 'function(component, event, helper) { component.set('v.mycolumns', [ {label: 'Thema', fieldName: 'Beschreibung__c', type: 'url', typeAttributes: {label: { fieldName: 'Beschreibung__c' }, target: '_blank'}}, {label: 'Thema__c', fieldName: 'Thema__c', type: 'picklist', fixedWidth: 160 }, ]); var action = component.get("c.loadMedia"); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var records =response.getReturnValue(); records.forEach(function(record){ }); component.set("v.media", records); } }); $A.enqueueAction(action); }': Source

COMPONENT
<aura:component controller="MediaController" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" >
    
    <aura:attribute name="recordId" type="Id" />    
    <aura:attribute name="mediathekList" type="List" default="Mediathek[]"/>
                                              
   
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>   
    <aura:attribute name="mycolumns" type="List"/>
  
        <div>
            <aura:if isTrue="{!not(empty(v.media))}">
                <lightning:datatable data="{!v.mediathekList }" 
                         columns="{!v.mycolumns }" 
                         keyField="Id"
                         hideCheckboxColumn="true"
                         />
                <aura:set attribute="else">
                    <div Style="text-align : center"> Keine Aufgaben</div>
                </aura:set>
            </aura:if>
        </div>
        
</aura:component>


JS
({
    doInit: function(component, event, helper) {
    
      
        	component.set('v.mycolumns', [
            {label: 'Thema', fieldName: 'Beschreibung__c', type: 'url',
            typeAttributes: {label: { fieldName: 'Beschreibung__c' }, target: '_blank'}},
                {label: 'Thema__c', fieldName: 'Thema__c', type: 'picklist', fixedWidth: 160 },
        ]);
        var action = component.get("c.loadMedia");
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                 
                });
                component.set("v.media", records);
            }
        });
        $A.enqueueAction(action);
            
       

})


APEX
public class MediaController {

       
//ÜBERFÄLLIG - Abfrage Tasks, wo das Activity Date abgelaufen und der Status "Not Completed" ist//
@AuraEnabled
public static List<Mediatheken> loadmedia(Id recordId){
    string userId = UserInfo.getUserId();
    return[SELECT Thema__c, Bezeichnung__c FROM Mediathek__c WHERE Typ__c = 'Printmaterial'];
}
}

 
Dushyant SonwarDushyant Sonwar
Looks like there is an issue in the mycolumns json Data Array

Try using the below code
 
({
    doInit: function(component, event, helper) {
    
      
        	var columnValue = [{"label":"Thema","fieldName":"Beschreibung__c","type":"url","typeAttributes":{"label":{"fieldName":"Beschreibung__c"},"target":"_blank"}},{"label":"Thema__c","fieldName":"Thema__c","type":"picklist","fixedWidth":160}];

			component.set('v.mycolumns', columnValue);
        var action = component.get("c.loadMedia");
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                 
                });
                component.set("v.media", records);
            }
        });
        $A.enqueueAction(action);
            
       

})


 
mukesh guptamukesh gupta
Hi JONATHAN,

Please use below JS code :-
 
({
    doInit: function(component, event, helper) {
    
      
        	component.set('v.mycolumns', [
            {label: 'Thema', fieldName: 'Beschreibung__c', type: 'url',
            typeAttributes: {label: { fieldName: 'Beschreibung__c' }, target: '_blank'}},
                {label: 'Thema__c', fieldName: 'Thema__c', type: 'picklist', fixedWidth: 160 },
        ]);
        var action = component.get("c.loadMedia");
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
               
                component.set("v.mediathekList", records);
            }
        });
        $A.enqueueAction(action);
            
       

})

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh