Giter VIP home page Giter VIP logo

Comments (8)

dmk99 avatar dmk99 commented on July 29, 2024 3

This is not directly supported, but is definitely a logical thing to implement.
One way that you could handle this is to add an index to each item in the data array. Then, when using DataTableCell return a custom View that colours the background based on data.index % 2 === 0.

Something like below. Note I have not tested the code, this is just for illustration.

                    <TableBody>
                        <DataTableCell getContent={(r) => <View style={{backgroundColor: `${r.index % 2 === 0 ? "red" : "blue"}`}}>{r.firstName}</View>}/>
                    ...
                    </TableBody>

from react-pdf-table.

deividkamui avatar deividkamui commented on July 29, 2024 1

@andrellgrillo try changing your table body to:

<TableBody >
        <DataTableCell getContent={(r) => {  
              return (  
                 <Text>{r.id}</Text>
              ); 
          }} />
         <DataTableCell getContent={(r) => r.descricao} />
         <DataTableCell getContent={(r) => r.pontuacao} />
</TableBody>

from react-pdf-table.

dmk99 avatar dmk99 commented on July 29, 2024

Development Notes:

In getContent, provide the index of the element.
Provide support for specifying styles for odd and even rows in TableBody.

from react-pdf-table.

deividkamui avatar deividkamui commented on July 29, 2024

In order to create a full colored cell you must use flexGrow: 1; if you don't use it the background-color does not cover all the cell content.

example:

<DataTableCell style={pdfStyles.dataTableRowCenter} weighting={0.1} getContent={(r: IEstatus) => {

    return (
          <View style={{ backgroundColor: r.Color, flexGrow: 1 }}>
             <Text style={{ color: "white" }}>
                 {r.Title}
             </Text>
          </View>
    );
 }} />

image

from react-pdf-table.

andrellgrillo avatar andrellgrillo commented on July 29, 2024

I didn't understand, because this solution didn't work for me.

This is not directly supported, but is definitely a logical thing to implement.
One way that you could handle this is to add an index to each item in the data array. Then, when using DataTableCell return a custom View that colours the background based on data.index % 2 === 0.

Something like below. Note I have not tested the code, this is just for illustration.

                    <TableBody>
                        <DataTableCell getContent={(r) => <View style={{backgroundColor: `${r.index % 2 === 0 ? "red" : "blue"}`}}>{r.firstName}</View>}/>
                    ...
                    </TableBody>

Error: Type mismatch
appendChild
C:/Users/user/Documents/Sistema/src/elements/Node.js:22

19 | if (child) {
20 | child.parent = this;
21 | this.children.push(child);

22 | this.layout.insertChild(child.layout, this.layout.getChildCount());
| ^ 23 | }
24 | }
25 |

import React, { useState, useEffect } from "react";
import {
  PDFViewer,
  Document,
  Page,
  StyleSheet,
  View,
} from "@react-pdf/renderer";
import {
  Table,
  TableHeader,
  TableCell,
  TableBody,
  DataTableCell,
} from "@david.kucsai/react-pdf-table";
import api from "./services/api";

import "./App.css";

const styles = StyleSheet.create({
  page: { paddingLeft: 30, paddingRight: 10, paddingTop: 10 },
});

function App() {
  const [loading, setLoading] = useState(false);
  const [condicoes, setCondicoes] = useState([]);

  useEffect(() => {
    async function loadCondicoes() {
      const result = await api.get("condicoes");
      setCondicoes(result.data);
      if (result.data) {
        setLoading(true);
        //console.log(secoes);
      }
    }

    loadCondicoes();
  }, [loading]);

  if (loading) {
    return (
      <div
        style={{
          width: "100%",
          justifyContent: "center",
          alignContent: "center",
          textAlign: "center",
        }}
      >
        <PDFViewer width="1000" height="600" className="app">
          <Document>
            <Page size="A4" style={styles.page}>
              <Table data={condicoes}>
                <TableHeader>
                  <TableCell>Id</TableCell>
                  <TableCell>Descrição</TableCell>
                  <TableCell>Pontuação</TableCell>
                </TableHeader>
                <TableBody >
                  <DataTableCell getContent={(r) => <View>{r.id}</View>} />
                  <DataTableCell getContent={(r) => r.descricao} />
                  <DataTableCell getContent={(r) => r.pontuacao} />
                </TableBody>
              </Table>
            </Page>
          </Document>
        </PDFViewer>
      </div>
    );
  }
  return null;
}

export default App;

from react-pdf-table.

andrellgrillo avatar andrellgrillo commented on July 29, 2024

Thank you!! @deividkamui , Problem resolved

from react-pdf-table.

hkar19 avatar hkar19 commented on July 29, 2024

This is not directly supported, but is definitely a logical thing to implement.
One way that you could handle this is to add an index to each item in the data array. Then, when using DataTableCell return a custom View that colours the background based on data.index % 2 === 0.

Something like below. Note I have not tested the code, this is just for illustration.

                    <TableBody>
                        <DataTableCell getContent={(r) => <View style={{backgroundColor: `${r.index % 2 === 0 ? "red" : "blue"}`}}>{r.firstName}</View>}/>
                    ...
                    </TableBody>

how do you get the index? i dont think it was defined in getContent's r param.

from react-pdf-table.

dmk99 avatar dmk99 commented on July 29, 2024

This is not directly supported, but is definitely a logical thing to implement.
One way that you could handle this is to add an index to each item in the data array. Then, when using DataTableCell return a custom View that colours the background based on data.index % 2 === 0.
Something like below. Note I have not tested the code, this is just for illustration.

                    <TableBody>
                        <DataTableCell getContent={(r) => <View style={{backgroundColor: `${r.index % 2 === 0 ? "red" : "blue"}`}}>{r.firstName}</View>}/>
                    ...
                    </TableBody>

how do you get the index? i dont think it was defined in getContent's r param.

This is a property on your row data.

from react-pdf-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.