Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `EuiDataGrid`'s default sort order property ([#2987](https://github.com/elastic/eui/pull/2987))
- Fixed `EuiDataGrid`'s pagination visibility when changing rows per page ([#2978](https://github.com/elastic/eui/pull/2978))
- Added `highlightAll` prop to `EuiHighlight` to highlight all matches ([#2957](https://github.com/elastic/eui/pull/2957))
- Added `showOnFocus` prop to `EuiScreenReaderOnly` to force display on keyboard focus ([#2976](https://github.com/elastic/eui/pull/2976))
Expand Down
3 changes: 3 additions & 0 deletions src-docs/src/views/datagrid/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
const columns = [
{
id: 'name',
defaultSortDirection: 'asc',
},
{
id: 'email',
Expand Down Expand Up @@ -49,6 +50,7 @@ const columns = [
},
{
id: 'date',
defaultSortDirection: 'desc',
},
{
id: 'amount',
Expand All @@ -59,6 +61,7 @@ const columns = [
},
{
id: 'version',
defaultSortDirection: 'desc',
initialWidth: 65,
isResizable: false,
},
Expand Down
101 changes: 56 additions & 45 deletions src/components/datagrid/column_sorting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const useColumnSorting = (
): ReactNode => {
const [isOpen, setIsOpen] = useState(false);
const [avilableColumnsisOpen, setAvailableColumnsIsOpen] = useState(false);

// prune any non-existant/hidden columns from sorting
useEffect(() => {
if (sorting) {
Expand Down Expand Up @@ -213,50 +212,62 @@ export const useColumnSorting = (
<div
className="euiDataGridColumnSorting__fieldList"
role="listbox">
{inactiveSortableColumns.map(({ id }) => (
<button
key={id}
className="euiDataGridColumnSorting__field"
aria-label={`${sortFieldAriaLabel} ${id}`}
role="option"
aria-selected="false"
data-test-subj={`dataGridColumnSortingPopoverColumnSelection-${id}`}
onClick={() => {
const nextColumns = [...sorting.columns];
nextColumns.push({ id, direction: 'asc' });
sorting.onSort(nextColumns);
}}>
<EuiFlexGroup
alignItems="center"
gutterSize="s"
component="span"
responsive={false}>
<EuiFlexItem grow={false}>
<EuiToken
iconType={
schemaDetails(id) != null
? getDetailsForSchema(
schemaDetectors,
schema[id].columnType
).icon
: 'tokenString'
}
color={
schemaDetails(id) != null
? getDetailsForSchema(
schemaDetectors,
schema[id].columnType
).color
: undefined
}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs">{id}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</button>
))}
{inactiveSortableColumns.map(
({ id, defaultSortDirection }) => {
return (
<button
key={id}
className="euiDataGridColumnSorting__field"
aria-label={`${sortFieldAriaLabel} ${id}`}
role="option"
aria-selected="false"
data-test-subj={`dataGridColumnSortingPopoverColumnSelection-${id}`}
onClick={() => {
const nextColumns = [...sorting.columns];
nextColumns.push({
id,
direction:
defaultSortDirection ||
(schemaDetails(id) &&
schemaDetails(id)!
.defaultSortDirection) ||
'asc',
});
sorting.onSort(nextColumns);
}}>
<EuiFlexGroup
alignItems="center"
gutterSize="s"
component="span"
responsive={false}>
<EuiFlexItem grow={false}>
<EuiToken
iconType={
schemaDetails(id) != null
? getDetailsForSchema(
schemaDetectors,
schema[id].columnType
).icon
: 'tokenString'
}
color={
schemaDetails(id) != null
? getDetailsForSchema(
schemaDetectors,
schema[id].columnType
).color
: undefined
}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs">{id}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</button>
);
}
)}
</div>
)}
</EuiI18n>
Expand Down
4 changes: 4 additions & 0 deletions src/components/datagrid/data_grid_schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export interface EuiDataGridSchemaDetector {
* Whether this column is sortable
*/
isSortable: boolean;
/**
* Default sort direction of the column
*/
defaultSortDirection?: 'asc' | 'desc';
}

const numericChars = new Set([
Expand Down
4 changes: 4 additions & 0 deletions src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export interface EuiDataGridColumn {
* Whether this column is sortable
*/
isSortable?: boolean;
/**
* Default sort direction of the column
*/
defaultSortDirection?: 'asc' | 'desc';
}

export interface EuiDataGridColumnVisibility {
Expand Down