Is it possible to disable default sorting in React Admin?
Asked Answered
A

1

9

I have simple question

Is it possible to disable default sorting by column id? Or at least change it globally?

Thanks for answer

EDIT:

To be more specific, I have REST API (OData) which returns "Id" instead of "id" so I have to set sort everytime I use related component to prevent undefined errors.

I would welcome option to disable default sort in related components.

Amenity answered 7/1, 2019 at 16:14 Comment(2)
Haven't you checked the props of related component?Hedgepeth
@amir well of course but I am looking for more global solution, default sort uses "id" property which is missing in my OData backend (there is "Id") so I have to manually set concrete sort everytime I use related component. Which is somehow annoying. I will edit answer to refllect this use caseAmenity
B
20

If you are looking for a solution to disable sort option for that column, you can use sortable={false}.

Example usage:

import React from 'react';
import { List, Datagrid, TextField } from 'react-admin';

export const PostList = (props) => (
<List {...props}>
    <Datagrid>
        <TextField source="id" sortable={false} />
        <TextField source="title" />
        <TextField source="body" />
    </Datagrid>
</List>
);

Or you can specify a default sort for the List.

export const PostList = (props) => (
    <List {...props} sort={{ field: 'published_at', order: 'DESC' }}>
    ...
    </List>
);
Benita answered 8/1, 2019 at 2:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.