Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/simple/src/posts/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import BookIcon from '@material-ui/icons/Book';
import Chip from '@material-ui/core/Chip';
import { withStyles } from '@material-ui/core/styles';
import React, { Children, Fragment, cloneElement } from 'react';
import lodashGet from 'lodash/get';
import { unparse as convertToCSV } from 'papaparse/papaparse.min';
import {
BooleanField,
BulkDeleteButton,
ChipField,
Datagrid,
DateField,
downloadCSV,
EditButton,
Filter,
List,
Expand Down Expand Up @@ -45,6 +48,14 @@ const PostFilter = props => (
</Filter>
);

const exporter = (posts) => {
const data = posts.map(post => ({
...post,
backlinks: lodashGet(post, 'backlinks', []).map(backlink => backlink.url),
}))
return downloadCSV(convertToCSV({ data }), 'posts');
};

const styles = theme => ({
title: {
maxWidth: '20em',
Expand Down Expand Up @@ -96,6 +107,7 @@ const PostList = withStyles(styles)(({ classes, ...props }) => (
bulkActionButtons={<PostListBulkActions />}
filters={<PostFilter />}
sort={{ field: 'published_at', order: 'DESC' }}
exporter={exporter}
>
<Responsive
small={
Expand Down