We will create a responsive table in React Native application, this table will be horizontally and vertically scrollable. Moreover, the Header of the table will be fixed while scrolling the table vertically or horizontally. Show To create the table component, we will be using the react-native-table-component plugin, Its a simple table component for React Native applications. Let’s start building table component. Table of ContentsPrerequisiteWe need following frameworks, tools, and packages.
Initiate React Native ProjectInstall the latest React Native CLI by typing the below command in the terminal.
Type command in the terminal to Install new React Native application.
Enter inside the project folder.
Install React Native Table Component PluginLet’s install the react-native-table-component package via npm by running the following command in the terminal.
Now, we are all set to start creating Android and iOS Table in React Native application. Build Simple Table Component in React NativeTo build a simple table component in React Native, we have to import the following services in the top section of the App.js file. Define constructor(props), super(props), and state inside the export default class App. Inside the state, we declare the Table’s header and dummy data that we will display in the Table.
Next, we will declare the render() method inside the export default class App. Here, we set the table view and add custom styling classes to style the table. We will also inject the data in the table and set the table header.
We have created the basic table in React Native and here is the table component code in App.js.
Style Table ComponentNow, we will learn on how to style table component. We have already imported StyleSheet API from from ‘react-native’ and defined the CSS class to style the table component similar like this style={styles.HeadStyle}. Here is the View we have defined to display and style the table.
Place the following code below the export default class App extends Component.
Check out the final code below.
Fixed Header + Horizontal & Vertical Scrollable Table ExampleNow, we will create a Table layout that supports horizontal & vertical scrolling and fixed header. This table will be a responsive table as well due to its adaptive approach that enhances the better user experience to visualise the data in mobile devices . Here is the final code for Responsive Table in React Native. 0Import ScrollView API in the header, we are populating some data into the table. All the table code goes inside the ScrollView component and set the horizontal property to true. Table PropertiesWe have used the following properties above to configure data table in React Native application. Data: Its an Array type of data that is displayed in the Table. ConclusionFinally, we have finished Table tutorial in React Native. We have learned how to create a simple table component and populate data in it. I hope you loved this tutorial. Please share it with others. Get the complete code for this tutorial on this GitHub repository. Have a good day and Happy coding! Digamber I am Digamber, a full-stack developer and fitness aficionado. I created this site to bestow my coding experience with newbie programmers. I love to write on JavaScript, ECMAScript, React, Angular, Vue, Laravel. Twitter GitHubRecommended Posts:How to Add Full Screen Background Image in React NativeReact Native Build & Validate Forms with Formik & YupReact Native Pick Images From Camera & Gallery ExampleReact Native Firebase – Login and User Registration TutorialReact Native StackNavigator Pass & Get Params to ScreenReact Native Navigation v5 Example TutorialCreate React Native Firebase CRUD App with FirestoreReact Native Firebase – Firebase Integration in React NativeReact Native Alert Example – Show Alert in React Native AppCreate Radio Button Component in React NativeReact Native Image Component Tutorial with ExamplesBuild React Native Custom Checkbox Component |