dohooo / react-native-table-component

🌱Build table for react native
MIT License
730 stars 188 forks source link

How to add numberOfLines for Cell component? #142

Closed aliwaqar981 closed 3 years ago

aliwaqar981 commented 3 years ago

Hi! Thankyou for this great package. My text is too large to be fit in a cell. Although I want to display text which can be appeared in two lines and then .... . Just Like Text component. How can I do that?

Current Behaviour

Simulator Screen Shot - iPhone 12 - 2021-06-09 at 12 15 21

mattslight commented 3 years ago

I looked in the source code and the Cell component is a smart wrapper for <Text ... /> so you can pass the standard text prop numberOfLines to Cell as

<Cell ...otherProps numberOfLines={1} />

You can structure your data like in the example provided:-

<Table>
  <Row data={tableHeaders} />
  {tableData.map((rowData, index) => (
    <TableWrapper key={index} style={styles.row}>
      {rowData.map((cellData, cellIndex) => (
        <Cell
          key={cellIndex}
          data={cellData}
          numberOfLines={1}
        />
      ))}
    </TableWrapper>
  ))}
</Table>
aliwaqar981 commented 3 years ago

Thanks @mattslight It seems like Cell props don't includes Text props but numberOfLines is working fine