最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to add scrollbar in horizontal in datatable react native paper? - Stack Overflow

programmeradmin3浏览0评论

Hy! I'm new in react native development and using expo-cli. I add a react-native-paper datatable in my app its working fine but I have many fields I want to scroll a screen in the horizontal direction but I can't understand who to do it. Kindly suggest to me what I can do for this problem.

import React from 'react';
import { StyleSheet, Text, View, ScrollView, TextInput, Button, } from 'react-native';
import { Card } from "react-native-shadow-cards";
import {DataTable} from  "react-native-paper"


const AllUsers = () =>{
    return(
        <View>
            <View style={styles.headSection}>
                <Text style={styles.titleHeading}>All Users</Text>
            </View>
            <ScrollView horizontal>
            <DataTable style={styles.table} >
                <DataTable.Header>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading}>Id</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Username</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >First Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Last Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} >  <Text style={styles.tableHeading} >Email</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >First Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Last Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} >  <Text style={styles.tableHeading} >Email</Text></DataTable.Title>
                    
                </DataTable.Header>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Pagination
                    page={1}
                    numberOfPages={3}
                    onPageChange={(page) => { console.log(page); }}
                    label="1-2 of 6"
                />
            </DataTable>
            </ScrollView>
        </View>
    )    
}
const styles = StyleSheet.create({
    table:{
        
    },
    headSection:{
        borderBottomWidth:2,
        borderColor:'black',
        paddingBottom:15,
        
    },
    titleHeading:{
        marginTop:50,
        fontWeight:'bold',
        marginHorizontal:167,
    },
    tableHeading:{
        fontWeight:'bold',
        color:'black',
    },
    header:{
        paddingLeft:0,
    },
});
export default AllUsers;

Here's above code is having three fields but I want to add more fields. but want to scroll in the horizontal direction.

Hy! I'm new in react native development and using expo-cli. I add a react-native-paper datatable in my app its working fine but I have many fields I want to scroll a screen in the horizontal direction but I can't understand who to do it. Kindly suggest to me what I can do for this problem.

import React from 'react';
import { StyleSheet, Text, View, ScrollView, TextInput, Button, } from 'react-native';
import { Card } from "react-native-shadow-cards";
import {DataTable} from  "react-native-paper"


const AllUsers = () =>{
    return(
        <View>
            <View style={styles.headSection}>
                <Text style={styles.titleHeading}>All Users</Text>
            </View>
            <ScrollView horizontal>
            <DataTable style={styles.table} >
                <DataTable.Header>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading}>Id</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Username</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >First Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Last Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} >  <Text style={styles.tableHeading} >Email</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >First Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Last Name</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} >  <Text style={styles.tableHeading} >Email</Text></DataTable.Title>
                    
                </DataTable.Header>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Pagination
                    page={1}
                    numberOfPages={3}
                    onPageChange={(page) => { console.log(page); }}
                    label="1-2 of 6"
                />
            </DataTable>
            </ScrollView>
        </View>
    )    
}
const styles = StyleSheet.create({
    table:{
        
    },
    headSection:{
        borderBottomWidth:2,
        borderColor:'black',
        paddingBottom:15,
        
    },
    titleHeading:{
        marginTop:50,
        fontWeight:'bold',
        marginHorizontal:167,
    },
    tableHeading:{
        fontWeight:'bold',
        color:'black',
    },
    header:{
        paddingLeft:0,
    },
});
export default AllUsers;

Here's above code is having three fields but I want to add more fields. but want to scroll in the horizontal direction.

Share Improve this question edited Apr 7, 2021 at 16:50 Adil Ijaz asked Apr 7, 2021 at 15:51 Adil IjazAdil Ijaz 3621 gold badge5 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

To enable horizontal scrolling, you can put the content you want to scroll in a ScrollView ponent with horizontal as a prop like this:

<ScrollView horizontal>
<DataTable style={styles.table} >
                <DataTable.Header>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading}>Id</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} > <Text style={styles.tableHeading} >Username</Text></DataTable.Title>
                    <DataTable.Title style={styles.header} >  <Text style={styles.tableHeading} >Email</Text></DataTable.Title>
                </DataTable.Header>
                <DataTable.Row>
                    <DataTable.Cell>1.</DataTable.Cell>
                    <DataTable.Cell>adiljaz02</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Row>
                    <DataTable.Cell>2.</DataTable.Cell>
                    <DataTable.Cell>adil09</DataTable.Cell>
                    <DataTable.Cell>[email protected]</DataTable.Cell>
                </DataTable.Row>
                <DataTable.Pagination
                    page={1}
                    numberOfPages={3}
                    onPageChange={(page) => { console.log(page); }}
                    label="1-2 of 6"
                />
            </DataTable>
</ScrollView>
发布评论

评论列表(0)

  1. 暂无评论