-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom column sort values for EuiInMemoryTable (#929)
* Added custom column sort values to EuiInMemoryTable * changelog * small code style tweak
- Loading branch information
1 parent
ffeea17
commit 97df3ce
Showing
9 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src-docs/src/views/tables/in_memory/in_memory_custom_sorting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { | ||
EuiInMemoryTable | ||
} from '../../../../../src/components'; | ||
|
||
const data = [ | ||
{ animal: 'snail', weight: 25, humanFriendlyWeight: '25g' }, | ||
{ animal: 'peregrine falcon', weight: 900, humanFriendlyWeight: '0.9kg' }, | ||
{ animal: 'small dog', weight: 4500, humanFriendlyWeight: '4.5kg' }, | ||
{ animal: 'brown bear', weight: 180000, humanFriendlyWeight: '180kg' }, | ||
{ animal: 'elephant', weight: 5440000, humanFriendlyWeight: '5440kg' }, | ||
{ animal: 'giraffe', weight: 1180000, humanFriendlyWeight: '1180kg' } | ||
]; | ||
|
||
export const Table = () => { | ||
const columns = [{ | ||
field: 'animal', | ||
name: 'Animal', | ||
sortable: true | ||
}, { | ||
field: 'humanFriendlyWeight', | ||
name: 'Weight', | ||
sortable: ({ weight }) => weight | ||
}]; | ||
|
||
const sorting = { | ||
sort: { | ||
field: 'humanFriendlyWeight', | ||
direction: 'asc', | ||
} | ||
}; | ||
|
||
return ( | ||
<EuiInMemoryTable | ||
items={data} | ||
columns={columns} | ||
pagination={false} | ||
sorting={sorting} | ||
/> | ||
); | ||
}; |
39 changes: 39 additions & 0 deletions
39
src-docs/src/views/tables/in_memory/in_memory_custom_sorting_section.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { | ||
EuiCode | ||
} from '../../../../../src/components'; | ||
import { GuideSectionTypes } from '../../../components'; | ||
import { renderToHtml } from '../../../services'; | ||
|
||
import { Table } from './in_memory_custom_sorting'; | ||
import { propsInfo } from './props_info'; | ||
|
||
const source = require('!!raw-loader!./in_memory_custom_sorting'); | ||
const html = renderToHtml(Table); | ||
|
||
export const customSortingSection = { | ||
title: 'In-Memory Table - Custom sort values', | ||
source: [ | ||
{ | ||
type: GuideSectionTypes.JS, | ||
code: source, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: html, | ||
} | ||
], | ||
text: ( | ||
<div> | ||
<p> | ||
Sometimes the value displayed in a column is not appropriate to use | ||
for sorting, such as pre-formatting values to be human-readable. In these | ||
cases it's possible to pass the <EuiCode>sortable</EuiCode> prop as | ||
a function instead of <EuiCode>true</EuiCode> or <EuiCode>false</EuiCode>. | ||
The function is used to extract or calculate the intended sort value | ||
for each <EuiCode>item</EuiCode>. | ||
</p> | ||
</div> | ||
), | ||
props: propsInfo, | ||
demo: <Table/> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters