Search code examples
admin-on-rest

How to add List behavior to ReferenceManyField?


I have a list of 6k entries related to a ressource.

I would like to be able to list, search and paginate over them in a TabbedForm/FormTab. ReferenceManyField shows a limited number of entries.

What is the recommended way to extend ReferenceManyField or use List instead?


Solution

  • According to those two issues: https://github.com/marmelab/admin-on-rest/issues/998 and https://github.com/marmelab/admin-on-rest/issues/561 you cannot use List in ReferenceManyField and the suggested way to do it is having a button that redirects you to the related List component with the proper filter.

    Example:

    class LinkToRelatedReviews extends React.Component {
        render() {
        return (<FlatButton
            primary
            label={ translate("Full list of reviews by user") }
            icon={<ReviewsIcon />}
            containerElement={
                <Link to={{
                    pathname: '/reviews',
                    search: stringify({ filter: JSON.stringify({ userId: [this.props.params.id] }), page: 1 }),
                }}
            />}
        />)
        }
    }
    
    export default LinkToRelatedReviews;
    

    Something like that can be put in UsersShow Component

    <LinkToRelatedReviews params={props.match.params}/>
    

    under DataGrid that doesn't provide pagination but can fetch some of the results for you.

    You can also see it in action by navigating to: https://marmelab.com/admin-on-rest-demo/#/segments and clicking Customers. This will redirect you to CustomersList filtered by the specific segment.