Allow to disable column sorting

Summary: Project: https://docs.google.com/document/d/1SbFrpvfIShX5npANNa1AkgHliR1M-VMLW5Q9RhREt94/edit#

Reviewed By: antonk52

Differential Revision: D45394048

fbshipit-source-id: 4255777d477f8240f52b5f82c28e922ef1011989
This commit is contained in:
Andrey Goncharov
2023-04-28 12:19:45 -07:00
committed by Facebook GitHub Bot
parent a819c77f18
commit 9d2de05723
2 changed files with 32 additions and 24 deletions

View File

@@ -121,6 +121,7 @@ export type DataTableColumn<T = any> = {
predefined?: boolean; predefined?: boolean;
}[]; }[];
inversed?: boolean; inversed?: boolean;
sortable?: boolean;
}; };
export interface TableRowRenderContext<T = any> { export interface TableRowRenderContext<T = any> {

View File

@@ -13,7 +13,7 @@ import {
Percentage, Percentage,
Width, Width,
} from '../../utils/widthUtils'; } from '../../utils/widthUtils';
import {memo, useRef} from 'react'; import {HTMLAttributes, memo, useRef} from 'react';
import {Interactive, InteractiveProps} from '../Interactive'; import {Interactive, InteractiveProps} from '../Interactive';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import React from 'react'; import React from 'react';
@@ -174,25 +174,26 @@ function TableHeadColumn({
}); });
}; };
let divProps: HTMLAttributes<HTMLDivElement> = {};
if (column.sortable) {
divProps = {
onClick: (e) => {
e.stopPropagation();
const newDirection =
sorted === undefined ? 'asc' : sorted === 'asc' ? 'desc' : undefined;
dispatch({
type: 'sortColumn',
column: column.key,
direction: newDirection,
});
},
role: 'button',
tabIndex: 0,
};
}
let children = ( let children = (
<Layout.Right center> <Layout.Right center>
<div <div {...divProps}>
onClick={(e) => {
e.stopPropagation();
const newDirection =
sorted === undefined
? 'asc'
: sorted === 'asc'
? 'desc'
: undefined;
dispatch({
type: 'sortColumn',
column: column.key,
direction: newDirection,
});
}}
role="button"
tabIndex={0}>
<Text type="secondary"> <Text type="secondary">
{column.title === undefined ? ( {column.title === undefined ? (
toFirstUpper(column.key) toFirstUpper(column.key)
@@ -201,12 +202,18 @@ function TableHeadColumn({
) : ( ) : (
column.title column.title
)} )}
<SortIcons {column.sortable ? (
direction={sorted} <SortIcons
onSort={(dir) => direction={sorted}
dispatch({type: 'sortColumn', column: column.key, direction: dir}) onSort={(dir) =>
} dispatch({
/> type: 'sortColumn',
column: column.key,
direction: dir,
})
}
/>
) : null}
</Text> </Text>
</div> </div>
<FilterIcon column={column} dispatch={dispatch} /> <FilterIcon column={column} dispatch={dispatch} />