在 react-native-table-component 中搜索

Searching in react-native-table-component

在搜索栏中输入文本时,它应该在 table 数据中搜索以显示与搜索键匹配的行,但我无法在 [=14] 中找到所需的确切组件=]反应本机。 谁能帮我解决这个问题? 这是代码:

export default function ExampleOne() {
    const { loading, error, data } = useQuery(GET_USER_DETAILS);
    const head = ["id", "Name", "email"];
    if (loading) return <Text>Loading</Text>;
    if (error) return <Text>{`Error! ${error.message}`}</Text>;
    console.log(data.getUsers);
    const tableData = data.Users.map(rowObj => {
    delete rowObj["__typename"];
    return Object.values(rowObj);
    });
    return (
    <View style={styles.container}>
      <Table borderStyle={{ borderWidth: 1, borderColor: "#c8e1ff" }}>
        <Row
          data={head}
          style={styles.head}
          flexArr={[3, 2, 2]}
          textStyle={styles.text}
        />

        <Rows data={tableData} flexArr={[3, 2, 2]} textStyle={styles.text} />
      </Table>
    </View>
  );
}

您可以使用 SearchBar from react-native-elementsonChangeText 搜索栏更新 table 查看数据

完整代码示例

export default class App extends React.Component {
  state = {
    search:"", 
    tableData: tableData: [
        ['1', '2', '3', '4'],
        ['a', 'b', 'c', 'd'],
        ['1', '2', '3', '3'],
        ['a', 'b', 'c', 'd']
      ],
  };

  updateSearch = search => {
    this.setState({ search });
    // update tableview data
  };

  render() {
    const { search } = this.state;

    return (
      <SearchBar
        placeholder="Type Here..."
        onChangeText={this.updateSearch}
        value={search}
      />
    );
  }