Comments (8)
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.
@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.
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.
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>
);
}} />
from react-pdf-table.
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 anindex
to each item in thedata
array. Then, when usingDataTableCell
return a customView
that colours the background based ondata.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.
Thank you!! @deividkamui , Problem resolved
from react-pdf-table.
This is not directly supported, but is definitely a logical thing to implement.
One way that you could handle this is to add anindex
to each item in thedata
array. Then, when usingDataTableCell
return a customView
that colours the background based ondata.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.
This is not directly supported, but is definitely a logical thing to implement.
One way that you could handle this is to add anindex
to each item in thedata
array. Then, when usingDataTableCell
return a customView
that colours the background based ondata.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 ingetContent
'sr
param.
This is a property on your row data.
from react-pdf-table.
Related Issues (20)
- Add yarn support HOT 1
- Table ignores padding of parent View. HOT 1
- Override width for a specific Row. HOT 1
- How to get row index? HOT 1
- How to merge cell HOT 1
- styling rows HOT 4
- TableCell and DataTableCell throws an error
- Can we achieve two tables side by sides in a single render HOT 1
- Can we add page breaks HOT 1
- Error when build the project
- Update peerDependencies HOT 6
- Request: Colspan And Rowspan
- need some description
- Possibility to set wrap on TableRow from code HOT 2
- I would like to know how to wrap this table?
- Support React 16, 17 and 18
- How to add header in every page?
- Consolidating react-pdf table packages HOT 2
- running into errors while installing HOT 1
- Error in Next js 13 App routes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-pdf-table.