-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DATA GRID] Add Column header menu (#3087)
Co-authored-by: Chandler Prall <chandler.prall@gmail.com> Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
- Loading branch information
1 parent
093f7d9
commit c03ab19
Showing
18 changed files
with
1,500 additions
and
81 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
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,107 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
import { fake } from 'faker'; | ||
|
||
import { EuiDataGrid, EuiAvatar } from '../../../../src/components/'; | ||
|
||
const columns = [ | ||
{ | ||
id: 'avatar', | ||
initialWidth: 40, | ||
isResizable: false, | ||
actions: false, | ||
}, | ||
{ | ||
id: 'name', | ||
initialWidth: 100, | ||
isSortable: true, | ||
actions: { | ||
showHide: false, | ||
}, | ||
}, | ||
{ | ||
id: 'email', | ||
isSortable: true, | ||
actions: { | ||
additional: [ | ||
{ | ||
iconType: 'heart', | ||
label: 'Send Email', | ||
size: 'xs', | ||
onClick: () => | ||
alert('🎵Return to sender, address unknown, no such number,...'), | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'city', | ||
isSortable: true, | ||
actions: { | ||
showHide: { | ||
iconType: 'cross', | ||
label: 'Remove column', | ||
}, | ||
}, | ||
}, | ||
{ | ||
id: 'country', | ||
}, | ||
{ | ||
id: 'account', | ||
}, | ||
]; | ||
|
||
const data = []; | ||
|
||
for (let i = 1; i < 5; i++) { | ||
data.push({ | ||
avatar: ( | ||
<EuiAvatar | ||
size="s" | ||
imageUrl={fake('{{internet.avatar}}')} | ||
name={fake('{{name.lastName}}, {{name.firstName}}')} | ||
/> | ||
), | ||
name: fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}'), | ||
email: fake('{{internet.email}}'), | ||
city: fake('{{address.city}}'), | ||
country: fake('{{address.country}}'), | ||
account: fake('{{finance.account}}'), | ||
}); | ||
} | ||
|
||
export default () => { | ||
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 }); | ||
|
||
const [visibleColumns, setVisibleColumns] = useState(() => | ||
columns.map(({ id }) => id) | ||
); | ||
|
||
const setPageIndex = useCallback( | ||
pageIndex => setPagination({ ...pagination, pageIndex }), | ||
[pagination, setPagination] | ||
); | ||
const setPageSize = useCallback( | ||
pageSize => setPagination({ ...pagination, pageSize, pageIndex: 0 }), | ||
[pagination, setPagination] | ||
); | ||
|
||
return ( | ||
<EuiDataGrid | ||
aria-label="DataGrid demonstrating column sizing constraints" | ||
columns={columns} | ||
columnVisibility={{ | ||
visibleColumns: visibleColumns, | ||
setVisibleColumns: setVisibleColumns, | ||
}} | ||
rowCount={data.length} | ||
renderCellValue={({ rowIndex, columnId }) => data[rowIndex][columnId]} | ||
pagination={{ | ||
...pagination, | ||
pageSizeOptions: [5, 10, 25], | ||
onChangeItemsPerPage: setPageSize, | ||
onChangePage: setPageIndex, | ||
}} | ||
/> | ||
); | ||
}; |
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
Oops, something went wrong.