I am new to React Native. My objective is to display this below array of objects in table format in React Native. I am using DataTable of React-Native-Paper.
var accounts=[
{
"accNumber": "56456454",
"accType": "D",
"productCode": "1454541",
"availBalance": "987436.46",
},
{
"accNumber": "12424345645",
"accType": "D",
"productCode": "154545641",
"availBalance": "500397.64",
},
{
"accNumber": "4554545664",
"accType": "D",
"productCode": "44545",
"availBalance": "2467.02",
}
]
I have tried this but still it is showing an error:
<DataTable>
<DataTable.Header>
<DataTable.Title >
<Text style={styles.text}>Account</Text>
</DataTable.Title>
<DataTable.Title >
<Text style={styles.text}>Code</Text>
</DataTable.Title>
<DataTable.Title >
<Text style={styles.text}>Available Balance</Text>
</DataTable.Title>
</DataTable.Header>
{
accounts.map(account=>{
return(
<DataTable.Row>
<DataTable.Cell>{account.accNumber}</DataTable.Cell>
<DataTable.Cell>{account.productCode}</DataTable.Cell>
<DataTable.Cell>{account.availBalance}</DataTable.Cell>
</DataTable.Row>
)
})}
</DataTable>
Kindly suggest the way to display accounts data in tabular format supported by React Native. Is there any other way to map the data in table format apart from DataTable?
Expected Result:
Account Code Available Balance
56456454 1454541 987436.46
12424345645 154545641 500397.64
4554545664 44545 2467.02