Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiDataGrid] Use displayAsText for column sort search and columns headers #4351

Merged
merged 3 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Fixed `EuiErrorBoundary` error message not showing in non-Chromium browsers ([#4324](https://github.com/elastic/eui/pull/4324))
- Fixed `EuiToolTip` closing during initial positioning period ([#4327](https://github.com/elastic/eui/pull/4327))
- Added `!default` to SASS variables of `EuiCollapsibleNav` ([#4335](https://github.com/elastic/eui/pull/4335))
- Fixed `EuiDataGrid` column property `displayAsText`. Column headers prefer `displayAsText` over `id`; `display` still takes precedence. If provided, the filter in the sort-popover will search against `displayAsText` instead of `id`. ([#4351](https://github.com/elastic/eui/pull/4351))


**Theme: Amsterdam**

Expand Down
10 changes: 9 additions & 1 deletion src-docs/src/views/datagrid/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const columns = [
},
{
id: 'email',
displayAsText: 'Email address',
initialWidth: 130,
cellActions: [
({ rowIndex, columnId, Component }) => {
const data = useContext(DataContext);
Expand All @@ -100,9 +102,11 @@ const columns = [
},
{
id: 'location',
displayAsText: 'Location',
},
{
id: 'account',
displayAsText: 'Account',
actions: {
showHide: { label: 'Custom hide label' },
showMoveLeft: false,
Expand Down Expand Up @@ -140,19 +144,23 @@ const columns = [
},
{
id: 'date',
displayAsText: 'Date',
defaultSortDirection: 'desc',
},
{
id: 'amount',
displayAsText: 'Amount',
},
{
id: 'phone',
displayAsText: 'Phone',
isSortable: false,
},
{
id: 'version',
displayAsText: 'Version',
defaultSortDirection: 'desc',
initialWidth: 65,
initialWidth: 70,
isResizable: false,
actions: false,
},
Expand Down
5 changes: 4 additions & 1 deletion src/components/datagrid/column_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ export const useDataGridColumnSelector = (
});

const filteredColumns = sortedColumns.filter(
(id) => id.toLowerCase().indexOf(columnSearchText.toLowerCase()) !== -1
(id) =>
(displayValues[id] || id)
.toLowerCase()
.indexOf(columnSearchText.toLowerCase()) !== -1
);

const isDragEnabled = allowColumnReorder && columnSearchText.length === 0; // only allow drag-and-drop when not filtering columns
Expand Down
10 changes: 7 additions & 3 deletions src/components/datagrid/data_grid_header_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
headerIsInteractive,
className,
} = props;
const { id, display } = column;
const { id, display, displayAsText } = column;

const width = columnWidths[id] || defaultColumnWidth;

Expand Down Expand Up @@ -308,12 +308,16 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
</EuiScreenReaderOnly>
)}
{!showColumnActions ? (
<div className="euiDataGridHeaderCell__content">{display || id}</div>
<div className="euiDataGridHeaderCell__content">
{display || displayAsText || id}
</div>
) : (
<button
className="euiDataGridHeaderCell__button"
onClick={() => setIsPopoverOpen(true)}>
<div className="euiDataGridHeaderCell__content">{display || id}</div>
<div className="euiDataGridHeaderCell__content">
{display || displayAsText || id}
</div>
<EuiPopover
className="euiDataGridHeaderCell__popover"
panelPaddingSize="none"
Expand Down