Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Fetch sql data into react-native table component

$
0
0

I need to display specific data - that i get from my sql server database - in table using react native

Please if someone know how to present data dynamic data in table ??

this is my react native page that help me to fetch data and present it (but not like I'm looking for)

 this.state = {
      tableHead: ['Mois','Le nom du client', 'Annee', "Chiffre d'affaire"],
      tableData: [

      ]
    }
  }
  componentDidMount(){
    return fetch('http://192.168.1.4/fetch.php',{
    method:'post',
    header:{
    'Accept':'application/json',
    'Content-type' :'application/json'
    },
    body:JSON.stringify()})
      .then((response) => response.json())
      .then((responseJson) => {

        this.setState({
          isLoading: false,
          dataSource: responseJson,
        }, function(){
        });

      })
      .catch((error) =>{
        console.error(error);
      });
  }
  render() {
    const state = this.state;
    return (
      <View style={styles.container}>
        <Table borderStyle={{borderWidth: 2, borderColor: '#c8e1ff'}}>
          <Row data={state.tableHead} style={styles.head} textStyle={styles.text}/>
          <Rows data={state.tableData} textStyle={styles.text}/>
        </Table>
        <FlatList
        data={this.state.dataSource}
        renderItem={({item}) => <Text>{item.Mois}{"\n"}{item.M500_NOM}{"\n"} {item.Annee } {"\n"}  {item.ChiffreAffaire}{"\n"}{"\n"}</Text>}
        keyExtractor={(item, index) => index.toString()}

        />
      </View>
    )
  }
}

And this is my app page (how my code shows in my app)


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>