ericrsmith35 / DatatableV2

28 stars 24 forks source link

QUESTION: ASYNC: Refresh Table to use latest Data #50

Closed AndyHaas closed 4 years ago

AndyHaas commented 4 years ago

@ericrsmith35, We are working with Milestones and having to do a ton of custom things just to show status and other fields from the milestone in LEX. One of the things we had was a report that we wanted to put on a Home Page. Except you can't put a report on a Home Page. So using LWC I am doing a SOQL query to get the data and return.

        console.log('UserId: ' + this.userId);
        console.log('fieldName: ' + this.fieldName);
        const recordValue = await getRecords({recordId: this.userId, objectName: 'CaseMilestone', fieldsToShow: this.fieldName})
        .catch( error => console.error( "error: ", error ) );
        if( recordValue ){
            console.log('hit');
            recordValue.forEach(record => {
                console.log('record: ', record);
                console.log('Records: '+ recordValue);
                let preparedRecord = {};
                preparedRecord.Id = record.id;
                preparedRecord.CaseStatus = record.Case.Status;
                preparedRecord.MilestoneStatus = record.Case.MilestoneStatus;
                preparedRecord.CaseNumber = record.Case.CaseNumber;
                preparedRecord.Priority = record.Case.Priority;
                preparedRecord.Origin = record.Case.Origin;
                preparedRecord.OpenDate = record.Case.CreatedDate;
                preparedRecord.MilestoneName = record.MilestoneType.Name;
                preparedRecord.TargetDate = record.TargetDate;
                preparedRecord.TargetResponseInMins = record.TargetResponseInMins;
                console.log('flattenRecord: ' + this.flattenRecord);
                this.flattenRecord.push(preparedRecord);
            });
            console.log('flattenRecord: ' + this.flattenRecord);
            return apexRefresh(this.flattenRecord);
        }
    } 

The issue I have is that the table comes back with no records as the data is still coming in.

At the time of everything finished compiled I do see in my console that flattenRecord returns 4 objects

flattenRecord: [object Object],[object Object],[object Object],[object Object]

I am running apexRefresh tying to refresh the LWC but not getting the page to load the datatable.

ericrsmith35 commented 4 years ago

Are you trying to display a datatable with an Apex Defined Object?

AndyHaas commented 4 years ago

Not necessarily an Apex Defined Object, since I need to get some Child data and show this on the data table I am building my own object to display the data.

ericrsmith35 commented 4 years ago

To use your own object, you should define it with an Apex Defined variable. See how to implement that so it can be displayed in the datatable component here: https://ericsplayground.wordpress.com/how-to-use-an-apex-defined-object-with-my-datatable-flow-component/