Skip to content

Commit

Permalink
[EuiDataGrid] Use displayAsText for column sort search and columns …
Browse files Browse the repository at this point in the history
…headers (#4351)

* Column headers use displayAsText (#4114)

If the `display` property isn't provided, then the column header should use the `displayAsText` property before falling back to `id`.
Docs example now shows `Email address` while keeping `email` id, and other columns now capitalised.

* Column search matches `displayAsText` (#4204)

Still uses `id` if `displayAsText` property not provided

* Added `displayAsText` changes to changelog
  • Loading branch information
j-m authored Dec 4, 2020
1 parent 506329d commit 1748f90
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
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

0 comments on commit 1748f90

Please sign in to comment.