javascript - 如何在数据表 react native 纸中添加水平滚动条?

标签 javascript android reactjs react-native react-native-paper

嘿!我是 React Native 开发和使用 expo-cli 的新手。我在我的应用程序中添加了一个react-native-paper数据表,它工作正常,但我有很多字段,我想在水平方向滚动屏幕,但我不明白该由谁来做。请向我建议我可以为这个问题做些什么。

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><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c3d38353035363d26726c6e1c3b313d3530723f3331" rel="noreferrer noopener nofollow">[email protected]</a></DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7716131e1b1e1d160d59474537101a161e1b5914181a" rel="noreferrer noopener nofollow">[email protected]</a></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><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b2a2f222722212a31657b790b2c262a222765282426" rel="noreferrer noopener nofollow">[email protected]</a></DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f392979a9f9a999289ddc3c1b3949e929a9fdd909c9e" rel="noreferrer noopener nofollow">[email protected]</a></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>adilijaz.02@gmail.com</DataTable.Cell>
                    <DataTable.Cell>Adil</DataTable.Cell>
                    <DataTable.Cell>IJaz</DataTable.Cell>
                    <DataTable.Cell><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b7b2bfbabfbcb7acf8e6e496b1bbb7bfbaf8b5b9bb" rel="noreferrer noopener nofollow">[email protected]</a></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;

上面的代码具有三个字段,但我想添加更多字段。但想要水平方向滚动。 Looks that

最佳答案

要启用水平滚动,您可以将要滚动的内容放在 ScrollView 组件中,并以水平作为 prop,如下所示:

<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><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4a4f424742414a51051b196b4c464a424705484446" rel="noreferrer noopener nofollow">[email protected]</a></DataTable.Cell>
                </DataTable.Row>
                <DataTable.Row>
                    <DataTable.Cell>2.</DataTable.Cell>
                    <DataTable.Cell>adil09</DataTable.Cell>
                    <DataTable.Cell><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aacbcec3c6c39a93eacdc7cbc3c684c9c5c7" rel="noreferrer noopener nofollow">[email protected]</a></DataTable.Cell>
                </DataTable.Row>
                <DataTable.Pagination
                    page={1}
                    numberOfPages={3}
                    onPageChange={(page) => { console.log(page); }}
                    label="1-2 of 6"
                />
            </DataTable>
</ScrollView>

关于javascript - 如何在数据表 react native 纸中添加水平滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66989668/

相关文章:

javascript - 在 Visual Studio 下编译时找不到模块

css - 删除 React Bootstrap 中的下拉箭头

javascript - 将图像 slider 高度设置为最小图像的高度

javascript - Jquery日期选择器范围选择不起作用

带有阴影的 Android 底部导航栏

android - 在拖动 View 时执行动画

javascript - AngularJS 复杂表头

javascript - 无法使用 jquery 和 twig 隐藏元素

java - 禁止从已安装的 Android 应用程序中获取 apk 文件

php - 如何通过 react js在php中发布数据