What is the best way to format my JSON data as a table on the screen?

I need to display my data in a table format at the bottom of the screen, as shown in the screenshot below.

Here is an example of the top part code:

This code snippet is also used for movies.

<View>
<Text key={item.symbol}>{item.symbol}<Text>
<Text key={item.open}>{item.open}<Text>
<Text key={item.close}>{item.close}<Text>

</View>

Currently, my screen looks like this:

https://i.stack.imgur.com/DAmCZ.png

I want to create a layout similar to the one shown below:

https://i.stack.imgur.com/iH1PM.png

The additional data displayed next to 'close' and 'high' values are retrieved from a JSON API.

My current code snippet is as follows:

let movie = ( 
  <View  style={styles.bottomdata}>
   <Text style={styles.text} key={item.name}>
      {item.name}
    </Text>
     <Text style={styles.text} key={item.open}>
      OPEN {item.open}
    </Text>
     <Text style={styles.text} key={item.close}>
      CLOSE{item.close}
    </Text>
   <Text style={styles.text} key={item.volumes}>
      VOLUME{item.volumes}
    </Text>
     <Text style={styles.text} key={item.low}>
     LOW {item.low}
    </Text>

    <Text style={styles.text} key={item.high}>
      HIGH{item.high}
    </Text>  
  </View>
)


  return (
    <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
      <View style={styles.container}>
       <View>{movie}</View>   
      </View>
    </TouchableWithoutFeedback>

   );
}



const styles = StyleSheet.create({
  text: {
    color: "black",
    backgroundColor: "white",
  },
  bottomdata:
  {
      marginTop:400,
      backgroundColor:"black",
  }
});

The movie represents the data displayed on the screen. How can I design it to match the desired layout? The top section should show the symbol name, close value, and high value just like the bottom section. Any suggestions on how to achieve this interface design?

Answer №1

To properly arrange the elements on a page, utilize views and testing to create a structured layout similar to a table. The code snippet below demonstrates how to align items in a row.

JSX

  <View style={{ flex: 1 }}>
  <View
    style={{
      flexDirection: 'row',
      backgroundColor: 'black',
      alignItems: 'center',
    }}>
    <Text style={{ flex: 0.5, color: 'white' }}>{item.symbol}</Text>
    <Text style={{ flex: 0.5, color: 'white' }} key={item.open}>{item.open}</Text>
    <Text
      style={{
        flex: 0.5,
        color: 'white',
        backgroundColor: 'red',
        marginVertical: 5,
        paddingHorizontal: 10,
        borderRadius: 10,
      }}
      key={item.close}>
      {item.close}
    </Text>
  </View>

  <View style={styles.bottomdata}>
    <Text style={[styles.text, { alignSelf: 'center' }]} key={item.name}>
      {item.name}
    </Text>
    <View style={styles.row}>
      <View style={styles.rowItem}>
        <Text style={styles.text}>OPEN</Text>
        <Text style={styles.text}>{item.open} </Text>
      </View>
      <View style={styles.rowItem}>
        <Text style={styles.text}>CLOSE</Text>
        <Text style={styles.text}>{item.close}</Text>
      </View>
    </View>
    <View style={styles.row}>
      <View style={styles.rowItem}>
        <Text style={styles.text}>LOW</Text>
        <Text style={styles.text}>{item.low} </Text>
      </View>
      <View style={styles.rowItem}>
        <Text style={styles.text}>HIGH</Text>
        <Text style={styles.text}>{item.high}</Text>
      </View>
    </View>
    <View style={styles.rowItem}>
      <Text style={styles.text}>VOLUME</Text>
      <Text style={styles.text}>{item.volumes}</Text>
    </View>
  </View>
</View>

Styles:

const styles = StyleSheet.create({
  text: {
    color: 'white',
  },
  bottomdata: {
    marginTop: 'auto',
    backgroundColor: 'black',
  },
  row: {
    flexDirection: 'row',
    width: '100%',
  },
  rowItem: {
    width: '50%',
    justifyContent: 'space-between',
    flexDirection: 'row',
    paddingHorizontal: 5,
  },
});

Answer №2

To effectively display information, create divs with appropriate alignments and retrieve data for the relevant field.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust Fontsize for Cell in Material UI Table

Is there a way to adjust the font size of each Cell in Material UI's Table? The code snippet below doesn't seem to be working as expected. const styles = { root: { fontSize: '200pt', }, body: { fontSize: '200pt' ...

conceal the bootstrap navigation bar while the page is being

Struggling to toggle a Bootstrap navbar on scroll? Need some guidance from the pros out there. I admit, my Bootstrap and jQuery skills are pretty basic. The browser console doesn't throw any errors, and I've experimented with fadeIn, fadeOut, add ...

Is it possible to adjust the position of a h2 heading on a particular webpage using CSS?

There is a situation where multiple pages contain h elements nested inside a standard container div class. When trying to edit a specific h2 element in a specific page using CSS, simply editing the h2 or the container does not work. Other methods attempte ...

Having difficulty accessing the reducer state within the container

Implementing Login Component: import React, { Component } from 'react' import { View, Text, StyleSheet, TextInput, TouchableOpacity } from ...

`Div Elements Overlapping`

Lately, I have been working on my personal portfolio and I encountered an issue with the contact form overlapping the footer. Can anyone provide some guidance on how to resolve this? Any help is greatly appreciated. https://i.stack.imgur.com/neIbs.gif ...

Exploring the possibilities of working with deeply nested components in React recursively

I have a basic to-do list with functionality for adding todos, toggling completion status, and deleting todos. My goal is to have the ability to nest todos infinitely. I've been able to display nested todos through recursion, but I'm struggling t ...

Tips for implementing SVG in background images on Internet Explorer

Having a similar issue to the one discussed in this thread. My background images are functioning properly on all browsers except for versions lower than IE10. After reading through that post, I created a background image in SVG format specifically for IE10 ...

Determining the Missing Focus: Discovering the Vacant '":focus'" in Jquery

I am currently working on jQuery and facing an issue with input fields that have assigned ID's and attached .blur() events. I am struggling to identify the specific item that has gained focus: $("#"+field).blur(function() { console.log ($(this).attr ...

Can someone guide me on how to align text to the bottom border of a page?

Is there a way to adjust the position of the header text ("bottom text") so that it appears just above the bottom border of the page? I have attempted modifying styles and classes within the footer, style, and h3 tags but have not had any success. Below ...

Jquery Ajax failing to retrieve a response

Here's the jQuery script I am using to fetch data from my server: $(".login_button").click(function () { var username = $(".username").val(); var userkey = $(".userkey").val(); $.ajax({ type: "GET", url: "http://192.168.0. ...

XMLHttpRequest response: the connection has been terminated

After developing a Flickr search engine, I encountered an issue where the call to the public feed or FlickrApi varies depending on the selection made in a drop-down box. The JSONP function calls provide examples of the returned data: a) jsonFlickrApi({"ph ...

Error encountered when attempting to send a JSON request using an Android application

Attempting to send a JSON Post request through my Android Application. Encountering some strange behavior. Below is the Android Code snippet: try { URL url = new URL(BASE_URL + params[0]); HttpURLConnection connection = (HttpURLConnection ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

Why isn't my React image updating its source right away? What are some solutions to this issue?

I currently have a basic <img> tag with a specified src attribute. <img src={src} /> When I update the src attribute from, let's say /1.jpg to /2.jpg, there is a delay in loading the new image. React still displays the old image (/1.jpg) ...

Enhancing User Experience with Flutter's Haptic Feedback for Long Press Operations

Is there a way to implement haptic feedback on long press in Flutter using the HapticFeedback class? I have been trying to use HapticFeedback.selectionClick() within my OnTapDown method, but unfortunately, no feedback is being generated. I made sure to i ...

Storing enumeration values with FMDB

I am facing an issue with using FMDB to serialize an object into a database. Specifically, I have a non-nullable int column where I want to store an enum value. Person.h @interface TreasureChest : NSObject { ... ComponentSorting componentSort ...

How to Ensure the Final Column in an Angular Bootstrap Row Occupies the Remaining Available Space

Within my Angular5 application, there is a container component used to display a row with multiple components arranged in n columns, as shown below: <div class="row mx-5 my-5 h-75 w-80"> <div class="col-md-4 col-lg-4 m-0 p-0" *ngIf="advanc ...

hide input type with minimal display

Can someone help me find the less equivalent to this css code snippet? I'm not familiar with less and this code is part of a larger global css file that includes generated code from all less files. input[type="checkbox"] { display: none; } Any a ...

Conceal certain tables within a container

On my SharePoint page, I have the following HTML structure: <div id="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView"> <table cellspacing="0" cellpadding="0" style="border-width:0;"> <table cellspacing="0" cellpadding="0" style="border-width: ...

Tips for transferring the checkbox value in a React component

Good Day! I am facing a challenge passing a Boolean value of the checkbox using onChange since it is already being used to toggle the checkbox value. I am unsure of an alternative way to achieve this. Any guidance provided would be greatly appreciated. T ...