im searching for a way to easily filter and maybe sort the following table. I tried filtering it with
{data.getInteressentListing.edges.filter(node.name => node.name.includes('J')).map(({node}) => (
but that did not work. Also i need something like a search bar filtering not only the name. It should filter for all colums at the same time. Maybe you can give me some sugestions or a easy solution on this.
Thanks in advance
Daniel
Here is the code of my working simple table
import React from 'react';
import gql from 'graphql-tag';
import { Query } from 'react-apollo';
import Table from 'react-bootstrap/Table'
export const GET_POSTS = gql`
query {
getInteressentListing {
edges {
node {
id
Name
Vorname
Quelle
Artikel
Land
Ort
Tel
Mobil
EMail
URL
Whatsapp
Telegram
Notizen
Geschlecht
}
}
}
}
`;
const rowStyles = (post, canEdit) => canEdit(post)
? { cursor: 'pointer', }
: {};
const PostViewer = ({ canEdit, onEdit }) => (
<Query query={GET_POSTS}>
{({ loading, data }) => !loading && (
<Table >
<thead>
<tr>
<th>Name</th>
<th>Vorname</th>
<th>Land</th>
<th>Ort</th>
<th>Tel.</th>
<th>Mobil</th>
<th>E-Mail</th>
<th>Geschlecht</th>
</tr>
</thead>
<tbody>
{data.getInteressentListing.edges.map(({node}) => (
<tr
key={node.id}
style={rowStyles(node, canEdit)}
onClick={() => canEdit(node) && onEdit(node)}
>
<td> {node.Name} </td>
<td> {node.Vorname} </td>
<td> {node.Land} </td>
<td> {node.Ort} </td>
<td> {node.Tel} </td>
<td> {node.Mobil} </td>
<td> {node.EMail} </td>
<td> {node.Geschlecht} </td>
</tr>
))}
</tbody>
</Table>
)}
</Query>
);
PostViewer.defaultProps = {
canEdit: () => true,
onEdit: () => null,
};
export default PostViewer;
That is the format my data looks like when i get it back. it has the node inside:
{
"data": {
"getInteressentListing": {
"edges": [
{
"node": {
"id": "1294",
"Name": "Felix",
"Vorname": "Hase",
"Quelle": "Facebook",
"Artikel": "Briefe",
"Land": "Deutschland",
"Ort": "KiKaLand",
"Tel": "+49 0256/659552",
"Mobil": "01525659565",
"EMail": "[email protected]",
"URL": "www.felixderhase.de",
"Whatsapp": true,
"Telegram": false,
"Notizen": "Läuft im Fernsehen",
"Geschlecht": "Divers"
}
},
{
"node": {
"id": "1295",
"Name": "Daniel",
"Vorname": "Morgner",
"Quelle": "eBay-Kleinanzeigen",
"Artikel": "Omega",
"Land": "Deutschland",
"Ort": "Musterort",
"Tel": "045692582",
"Mobil": "015412,0",
"EMail": "[email protected]",
"URL": "www.daniel.de",
"Whatsapp": false,
"Telegram": true,
"Notizen": "asdasd",
"Geschlecht": "Männlich"
}
},
{
"node": {
"id": "1296",
"Name": "Muster",
"Vorname": "Max",
"Quelle": "eBay-Kleinanzeigen",
"Artikel": "Musterartikel",
"Land": "Musterland",
"Ort": "Musterort",
"Tel": "+49255225488",
"Mobil": "+49536256",
"EMail": "[email protected]",
"URL": "www.mustermann.org",
"Whatsapp": true,
"Telegram": null,
"Notizen": "Hat viele Muster",
"Geschlecht": "Männlich"
}
},
{
"node": {
"id": "1297",
"Name": "",
"Vorname": "Peter",
"Quelle": null,
"Artikel": "Steine",
"Land": "Deutschland",
"Ort": "Musterort",
"Tel": "07228562345",
"Mobil": "01525654654654",
"EMail": "[email protected]",
"URL": "peter-walter.de",
"Whatsapp": null,
"Telegram": null,
"Notizen": "Verkauft Steine",
"Geschlecht": "Männlich"
}
},
{
"node": {
"id": "1298",
"Name": "Jakob",
"Vorname": "Hund",
"Quelle": null,
"Artikel": "Hundefutter",
"Land": "Traumland",
"Ort": "Bagdad",
"Tel": "0152519188723",
"Mobil": "025105153",
"EMail": "[email protected]",
"URL": null,
"Whatsapp": null,
"Telegram": true,
"Notizen": "Ist ein Hund",
"Geschlecht": "Männlich"
}
}
]
}
}
}
I request the data in my Query see code above
2
Answers
Step 1: I tried with mock data in the state
Step 2: Input change input to set on
state
Step 3: Written the filter function like below inside the
render
methodStep 4: Finally the
html
template will be in render method like below,DEMO
To search the entire row instead of a single field the user can actually do this based on the: