Topic: Datatable update problem

tpmai free asked 2 years ago


Expected behavior

I`m trying to use the update method of the datatable

Actual behavior

Error in console:

Uncaught TypeError: asyncTable.update is not a function
at (index):...

Resources (screenshots, code snippets etc.)

const columns = [
  { label: 'Address', field: 'address' },
  { label: 'Company', field: 'company' },
  { label: 'Email', field: 'email' },
  { label: 'Name', field: 'name' },
  { label: 'Phone', field: 'phone' },
  { label: 'Username', field: 'username' },
  { label: 'Website', field: 'website' },
];

const asyncTable = new mdb.Datatable(
  document.getElementById('datatable'),
  {
    columns,
  },
  { loading: true }
);

fetch('https://jsonplaceholder.typicode.com/users')
  .then((response) => response.json())
  .then((data) => {
    asyncTable.update(
      {
        rows: data.map((user) => ({
          ...user,
          address: `${user.address.city}, ${user.address.street}`,
          company: user.company.name,
        })),
      },
      { loading: false }
    );
  });

Michał Duszak staff answered 2 years ago


Hello, I have copy/pasted your code and eveything works fine for me. Could you performconsole.log(asyncTable) command and show me the output of your console?


tpmai free commented 2 years ago

Thank you for your help! Thanks to the proposed output in the log, I found an error in my code.


FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Closed

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.10.1
  • Device: PC
  • Browser: Opera, Firefox, Chrome
  • OS: Win
  • Provided sample code: No
  • Provided link: No