React: How to implement datatables from react, using data from server

React: How to implement datatables from react, using data from server

marcfernandezmarcfernandez Posts: 1Questions: 1Answers: 0

React DataTables implementation. I've looked online to try and figure out how to initialized a table if I'm calling a database. All I've seen are examples of hard coded data sets. ex const dataSet =[sample data]

constructor(props) {
    super(props);
    this.state = {
      dataSet:[],
        columns: [
          { title: "ID", dataSet: "ID" },
          { title: "First", dataSet: "first_name" },
          { title: "Last",  dataSet: "last_name" },
          { title: "Email", dataSet: "email" },
          { title: "Phone", dataSet: "phone_number" },
          { title: "Location", dataSet: "location" }
        ], 
    };
  }
    componentDidMount() {
      fetch("http://localhost:4000/dataSet/")



...
return (
     
        <SAMPLETABLE columns={columns} data={dataSet}>

    );

is this the correct way to set this up?

Answers

  • etilleyetilley Posts: 31Questions: 4Answers: 0
    edited April 2020

    Can you add code to allow selection by row with this method?

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    This thread might help - it discusses ajax source Data with React.js.

    Colin

This discussion has been closed.