2

I have created a table with react bootstrap table next and I try to use the defaultSorted features. Here is an example from the doc:

import BootstrapTable from 'react-bootstrap-table-next';

const columns = [{
  dataField: 'id',
  text: 'Product ID',
  sort: true
}, {
  dataField: 'name',
  text: 'Product Name',
  sort: true
}, {
  dataField: 'price',
  text: 'Product Price',
  sort: true
}];

const defaultSorted = [{
  dataField: 'name',
  order: 'desc'
}];

<BootstrapTable
  keyField="id"
  data={ products }
  columns={ columns }
  defaultSortDirection="asc"
/>

What I don't understand is where to use the defaultSorted constant? Should I add it to one of my column or in the bootstraptable? I have tried different solution and none of them seems to works. Thank you for your help.

2 Answers 2

2

defaultSorted is an attribute on BootstrapTable itself. The trick here is to use the same column name for which you have 'sort: true' added.

You can have a look at a sandbox demo here.

Sign up to request clarification or add additional context in comments.

Comments

1
// <BootstrapTable sort={ { columnName, order} } />

Example:

<BootstrapTable sort={ { dataField: 'firstName', order: 'desc' } } />

Make sure to give the exact column name.

1 Comment

Any idea, if it will work if the field is a date field ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.