0

So, I have a API which returns the data which should be shown in table with datatable option. I'm using 'mdbreact' to use datatable. But there is no documentation about pushing array variables into rows of datatables. How to push my array variables into rows of datatables ? My code :

import React, { Component } from 'react';
import { MDBDataTable } from 'mdbreact';
class DummyTest extends Component {

DummyFunc() {
    var data = {
                            columns: [

                                {
                                    label: 'Location',
                                    field: 'Location',
                                    sort: 'asc',
                                    width: 150
                                },
                                {
                                    label: 'Entry Time',
                                    field: 'EntryTime',
                                    sort: 'asc',
                                    width: 150
                                },
                                {
                                    label: 'Exit Time',
                                    field: 'ExitTime',
                                    sort: 'asc',
                                    width: 150
                                },
                            ],
                            rows: [
                            ]
                        };
                        const datatableProps = {data, rows: datas}; 


}

In return

<MDBDataTable
                        striped
                        bordered
                        hover
                        data={datatableProps}
                        />
Jee Mok
  • 6,157
  • 8
  • 47
  • 80
farooq
  • 1,603
  • 2
  • 17
  • 33
  • after fetching data from API you can set data and access rows from the state right? – uday Jan 03 '20 at 06:47
  • I can able to get the datas But I don't know how to push these values into `rows` of datatables . If I try to push, It accepts the last value of that data only – farooq Jan 03 '20 at 06:49

1 Answers1

1

you can update the rows data after fetching it from the API. sample using hooks.

something like this.setState({datatableProps: ...datatableProps, rows: API_ROWD_ATA})

uday
  • 1,421
  • 10
  • 19