I am trying to display two lightning datatables on a page. For the first one, I want to display only first row from the data I receive. Use case Scenario is to get most recent event data. For the second table, I would like to display all data. When I get my data, I am adding first element to variable mostRecent and I could see it has value in console. Second table works fine but first one does not. I do not understand why it won't render anything for the first table. To show an example, I have created this code using LWC component Reference guide for Datatable.

    <div style="height: 300px;">
        <template if:true={mostRecent}>
        <template if:true={data}>


import { LightningElement, track } from 'lwc';
import fetchDataHelper from './fetchDataHelper';

const columns = [
    { label: 'Label', fieldName: 'name' },
    { label: 'Website', fieldName: 'website', type: 'url' },
    { label: 'Phone', fieldName: 'phone', type: 'phone' },
    { label: 'Balance', fieldName: 'amount', type: 'currency' },
    { label: 'CloseAt', fieldName: 'closeAt', type: 'date' },

export default class BasicDatatable extends LightningElement {
    data = [];
    @track mostRecent = [];
    columns = columns;

    // eslint-disable-next-line @lwc/lwc/no-async-await
    async connectedCallback() {
        const data = await fetchDataHelper({ amountOfRecords: 100 });
        this.data = data;


const recordMetadata = {
    name: 'name',
    email: 'email',
    website: 'url',
    amount: 'currency',
    phone: 'phoneNumber',
    closeAt: 'dateInFuture',

export default function fetchDataHelper({ amountOfRecords }) {
    return fetch('https://data-faker.herokuapp.com/collection', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=utf-8',
        body: JSON.stringify({
    }).then((response) => response.json());

1 Answer 1


This feels like it might be a bug; track isn't detecting the change to the array. I'll ask around. In the meantime, you can fix this by using an explicit array constructor:

this.mostRecent = [data[0]];


Edit: From the comments, it appears this was never supported, and I just didn't realize that. Always create a fresh array using whatever appropriate method (Array.map, Array.flat, etc).

  • 3
    I have always found it to work like this. push() does not work for tracked variables. Pushing to a local variable and then setting the tracked variable does. let tracked = []; tracked.push(data[0]); this.trackedVar = tracked;
    – CyberJus
    Commented Aug 4, 2021 at 0:30
  • @CyberJus Yeah, you're creating a new object, so the runtime picks up on the change of objects. I presumed Array.push would work with track, but I personally never use it, as I always copy a fresh array. Do you happen to know if this is documented anywhere before I go off making a Bug for it?
    – sfdcfox
    Commented Aug 4, 2021 at 1:00
  • Not super clear based on this: lwc.dev/guide/javascript_reactive#reactive-data-types Says it observes changes but push does not qualify as an observed change. Interesting that after setting the this.trackedVar, this works as expected to change the value => this.trackedVar[0] = data[1];
    – CyberJus
    Commented Aug 4, 2021 at 12:55
  • @CyberJus Right. In the example, they show how setHours doesn't affect the render, similar behavior with push, I suppose. I agree, it could be clarified better.
    – sfdcfox
    Commented Aug 4, 2021 at 13:08
  • @sfdcfox I see what the issue was. thank you, your solution works!
    – jejejean
    Commented Aug 4, 2021 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .