DEV Community

Supriya Kumari
Supriya Kumari

Posted on

DynamicTable

Hello, this is my code to create a dynamic table in react js, and this is working fine, but this component is data-dependent, here I am using field name with an object (obj.brand), I want to make it data-independent, how I should bind data for that, please help.

render() {

var header = Object.keys(this.state.data[0]);

const tableHeader = header && header.map(val=>

{

return (

{val});

});

const tableData = this.state.data && this.state.data.map(obj=>

{

return (




{obj.Brand}


{obj.Variety}



{obj.Style}


{obj.Country}


{obj.Stars}


{obj.Top_Ten}


);

});

return (









{tableHeader}










{tableData}




);

}

Top comments (0)