Skip to content

Commit

Permalink
feat: Optimize table sorting hot spots
Browse files Browse the repository at this point in the history
  • Loading branch information
YyumeiZhang committed Aug 15, 2024
1 parent b5976e5 commit 0f39595
Show file tree
Hide file tree
Showing 33 changed files with 186 additions and 34 deletions.
1 change: 1 addition & 0 deletions content/show/table/index-en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5418,6 +5418,7 @@ import { Table } from '@douyinfe/semi-ui';
| renderFilterDropdown | Custom filter dropdown panel, for usage details, see [Custom Filter Rendering](#Custom-Filter-Rendering) | (props?: RenderFilterDropdownProps) => React.ReactNode; | - | **2.52.0** |
| renderFilterDropdownItem | Customize the rendering method of each filter item. For usage details, see [Custom Filter Item Rendering](#Custom-Filter-Item-Rendering) | ({ value: any, text: any, onChange: Function, level: number, ...otherProps }) => ReactNode | - | **1.1.0** |
| resize | Whether to enable resize mode, this property will take effect only after Table resizable is enabled | boolean | | **2.42.0** |
| showSortTooltip | Whether to display sorting tips | boolean | true | **2.65.0** |
| sortChildrenRecord | Whether to sort child data locally | boolean | | **0.29.0** |
| sortOrder | The controlled property of the sorting, the sorting of this control column can be set to 'ascend'\|'descended '\|false | boolean | false |
| sorter | Sorting function, local sorting uses a function (refer to the compareFunction of Array.sort), requiring a server-side sorting can be set to true. **An independent dataIndex must be set for the sort column, and an independent key must be set for each data item in the dataSource** | boolean\|(r1: RecordType, r2: RecordType, sortOrder: 'ascend' \| 'descend') => number | true |
Expand Down
1 change: 1 addition & 0 deletions content/show/table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5549,6 +5549,7 @@ import { Table } from '@douyinfe/semi-ui';
| sortOrder | 排序的受控属性,外界可用此控制列的排序,可设置为 'ascend'\|'descend'\|false | boolean\| string | false |
| sorter | 排序函数,本地排序使用一个函数(参考 Array.sort 的 compareFunction),需要服务端排序可设为 true。**必须给排序列设置一个独立的 dataIndex,必须为 dataSource 里面的每条数据项设置独立的 key** | boolean\|(r1: RecordType, r2: RecordType, sortOrder: 'ascend' \| 'descend') => number | true |
| sortIcon | 自定义 sort 图标,返回的节点控制了整个排序按钮,包含升序和降序。需根据 sortOrder 控制高亮行为 | (props: { sortOrder }) => ReactNode | | **2.50.0** |
| showSortTooltip | 是否展示排序提示 | boolean | true | **2.65.0** |
| title | 列头显示文字。传入 function 时,title 将使用函数的返回值;传入其他类型,将会和 sorter、filter 进行聚合。需要搭配 useFullRender 获取函数类型中的 filter 等参数 | ReactNode\|({ filter: ReactNode, sorter: ReactNode, selection: ReactNode }) => ReactNode | | Function 类型需要**0.34.0** |
| useFullRender | 是否完全自定义渲染,用法详见[完全自定义渲染](#完全自定义渲染), 开启此功能会造成一定的性能损耗 | boolean | false | **0.34.0** |
| width | 列宽度 | string \| number | |
Expand Down
2 changes: 2 additions & 0 deletions packages/semi-foundation/table/animation.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$transition_duration-table_body-bg: var(--semi-transition_duration-none); // 表格-背景颜色-动画持续时间
$transition_function-table_body-bg: var(--semi-transition_function-easeOut); // 表格-背景颜色-过渡曲线
$transition_delay-table_body-bg: 0ms; // 表格-背景颜色-延迟时间
$transition_duration-table_row-head-bg: 0.1s; // 表格-行头-背景颜色-动画持续时间
$transition_function-table_row-head-bg: linear; // 表格-行头-背景颜色-过渡曲线
9 changes: 9 additions & 0 deletions packages/semi-foundation/table/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ $module: #{$prefix}-table;
// word-break: break-all;
// word-wrap: break-word;
position: relative;
transition: background-color $transition_duration-table_row-head-bg $transition_function-table_row-head-bg;

&-clickSort {
cursor: pointer;
&:hover {
background: var(--semi-color-fill-0),
}
}


&.#{$module}-cell-fixed {
&-left,
Expand Down
5 changes: 4 additions & 1 deletion packages/semi-ui/locale/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export interface Locale {
};
Table: {
emptyText: string;
pageText: string
pageText: string;
descend: string;
ascend: string;
cancelSort: string
};
Select: {
emptyText: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'لا نتيجة',
pageText: 'عرض ${currentStart} إلى ${currentEnd} من ${total}',
descend: 'انقر للهبوط',
ascend: 'انقر للصعود',
cancelSort: 'إلغاء الترتيب',
},
Select: {
emptyText: 'لا نتيجة',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'Kein Ergebnis',
pageText: 'Anzeigen ${currentStart} bis ${currentEnd} von ${total}',
descend: 'Klicken, um absteigend zu sortieren',
ascend: 'Klicken, um aufsteigend zu sortieren',
cancelSort: 'Sortierung abbrechen',
},
Select: {
emptyText: 'Kein Ergebnis',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/en_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'No Result',
pageText: 'Showing ${currentStart} to ${currentEnd} of ${total}',
descend: 'Click to descend',
ascend: 'Click to ascend',
cancelSort: 'Cancel sorting',
},
Select: {
emptyText: 'No Result',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'No Result',
pageText: 'Showing ${currentStart} to ${currentEnd} of ${total}',
descend: 'Click to descend',
ascend: 'Click to ascend',
cancelSort: 'Cancel sorting',
},
Select: {
emptyText: 'No Result',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const locale: Locale = {
Table: {
emptyText: 'Sin resultados',
pageText: 'Mostrando del ${currentStart} al ${currentEnd} de ${total}',
descend: 'Hacer clic para descender',
ascend: 'Hacer clic para ascender',
cancelSort: 'Cancelar ordenación',
},
Select: {
emptyText: 'Sin resultados',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'Aucun Résultat',
pageText: 'Montrant ${currentStart} to ${currentEnd} of ${total}',
descend: 'Cliquez pour descendre',
ascend: 'Cliquez pour monter',
cancelSort: 'Annuler le tri',
},
Select: {
emptyText: 'Aucun Résultat',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/id_ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'Tidak ada Hasil',
pageText: 'Tampilkan halaman ${currentStart} sampai ${currentEnd} dari ${total}',
descend: 'Klik untuk menurun',
ascend: 'Klik untuk menaik',
cancelSort: 'Batalkan penyortiran',
},
Select: {
emptyText: 'Tidak ada Hasil',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'Nessun risultato',
pageText: 'Mostra ${currentStart} a ${currentEnd} di ${total}',
descend: 'Clicca per discendere',
ascend: 'Clicca per ascendere',
cancelSort: 'Annulla ordinamento',
},
Select: {
emptyText: 'Nessun risultato',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/ja_JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const local: Locale = {
Table: {
emptyText: 'データがありません',
pageText: '第 ${currentStart} 条から第 ${currentEnd} 条まで表示します。計 ${total} 条',
descend: 'クリックして降順',
ascend: 'クリックして昇順',
cancelSort: 'ソートのキャンセル',
},
Select: {
emptyText: 'データがありません',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/ko_KR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const local: Locale = {
Table: {
emptyText: '결과 없음',
pageText: '${total} 중 ${currentStart}-${currentEnd}',
descend: '내림차순을 보려면 클릭하세요',
ascend: '오름차순을 보려면 클릭하세요',
cancelSort: '정렬 취소',
},
Select: {
emptyText: '결과 없음',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/ms_MY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'Tiada kandungan',
pageText: 'Papar halaman ${currentStart} hingga ${currentEnd} daripada ${total}',
descend: 'Klik untuk menurun',
ascend: 'Klik untuk menaik',
cancelSort: 'Batal mengurutkan',
},
Select: {
emptyText: 'Tiada kandungan',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/nl_NL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ const local: Locale = {
Table: {
emptyText: 'Geen resultaten gevonden',
pageText: '${currentStart} tot ${currentEnd} van ${total} wordt weergegeven',
descend: 'Klik om af te dalen',
ascend: 'Klik om op te stijgen',
cancelSort: 'Sorteren annuleren',
},
Select: {
emptyText: 'Geen resultaten gevonden',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/pl_PL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const local: Locale = {
Table: {
emptyText: 'Nie znaleziono żadnych wyników',
pageText: 'Wyświetlanie od ${currentStart} do ${currentEnd} z ${total}',
descend: 'Kliknij, aby sortować malejąco',
ascend: 'Kliknij, aby sortować rosnąco',
cancelSort: 'Anuluj sortowanie',
},
Select: {
emptyText: 'Nie znaleziono żadnych wyników',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const local: Locale = {
Table: {
emptyText: 'Não há dados',
pageText: 'Mostrando ${currentStart} - ${currentEnd} ,de ${total}',
descend: 'Clique para descrescer',
ascend: 'Clique para crescer',
cancelSort: 'Cancelar classificação',
},
Select: {
emptyText: 'Não há dados',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const local: Locale = {
Table: {
emptyText: 'Nici un rezultat',
pageText: 'Arată ${currentStart} la ${currentEnd} de ${total}',
descend: 'Faceți clic pentru a coborî',
ascend: 'Faceți clic pentru a urca',
cancelSort: 'Anulați sortarea',
},
Select: {
emptyText: 'Nici un rezultat',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/ru_RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const local: Locale = {
Table: {
emptyText: 'Нет результата',
pageText: 'Отображение ${currentStart} до ${currentEnd} из ${total}',
descend: 'Щелкните, чтобы упорядочить по убыванию',
ascend: 'Щелкните, чтобы упорядочить по возрастанию',
cancelSort: 'Отменить сортировку',
},
Select: {
emptyText: 'Нет результата',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/sv_SE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const local: Locale = {
Table: {
emptyText: 'Inga resultat hittades',
pageText: 'Visar ${currentStart} till ${currentEnd} av ${total}',
descend: 'Klicka för att sortera fallande',
ascend: 'Klicka för att sortera stigande',
cancelSort: 'Avbryt sortering',
},
Select: {
emptyText: 'Inga resultat hittades',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/th_TH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const local: Locale = {
Table: {
emptyText: 'ไม่มีข้อมูล',
pageText: 'แสดงรายการ ${currentStart} - ${currentEnd} จาก ${total}',
descend: 'คลิกเพื่อเรียงจากมากไปหาน้อย',
ascend: 'คลิกเพื่อเรียงจากน้อยไปหามาก',
cancelSort: 'ยกเลิกการเรียงลำดับ',
},
Select: {
emptyText: 'ไม่มีข้อมูล',
Expand Down
6 changes: 5 additions & 1 deletion packages/semi-ui/locale/source/tr_TR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ const local: Locale = {
{
emptyText: 'Henüz veri yok',
pageText:
'${currentStart} öğesini görüntüle - ${currentEnd} öğe, toplam ${total} öğe '
'${currentStart} öğesini görüntüle - ${currentEnd} öğe, toplam ${total} öğe ',
descend: 'Azalan sıralama için tıklayın',
ascend: 'Artan sıralama için tıklayın',
cancelSort: 'Sıralamayı iptal et',

},
Select: { emptyText: 'Henüz veri yok', createText: 'Oluştur' },
Cascader: { emptyText: 'Henüz veri yok' },
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/vi_VN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const local: Locale = {
Table: {
emptyText: 'Không kết quả',
pageText: 'Hiển thị ${currentStart} đến ${currentEnd} trong tổng số ${total}',
descend: 'Nhấp để sắp xếp giảm dần',
ascend: 'Nhấp để sắp xếp tăng dần',
cancelSort: 'Hủy sắp xếp',
},
Select: {
emptyText: 'Không kết quả',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const local: Locale = {
Table: {
emptyText: '暂无数据',
pageText: '显示第 ${currentStart} 条-第 ${currentEnd} 条,共 ${total} 条',
descend: '点击降序',
ascend: '点击升序',
cancelSort: '取消排序',
},
Select: {
emptyText: '暂无数据',
Expand Down
3 changes: 3 additions & 0 deletions packages/semi-ui/locale/source/zh_TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const local: Locale = {
Table: {
emptyText: '暫無數據',
pageText: '顯示第 ${currentStart} 條-第 ${currentEnd} 條,共 ${total} 條',
descend: '點擊降序',
ascend: '點擊升序',
cancelSort: '取消排序',
},
Select: {
emptyText: '暫無數據',
Expand Down
1 change: 1 addition & 0 deletions packages/semi-ui/table/ColumnShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export default {
title: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
useFullRender: PropTypes.bool,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
showSortTooltip: PropTypes.bool,
};
43 changes: 30 additions & 13 deletions packages/semi-ui/table/ColumnSorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { IconCaretup, IconCaretdown } from '@douyinfe/semi-icons';

import { cssClasses, strings } from '@douyinfe/semi-foundation/table/constants';

import { SortIcon, SortOrder } from './interface';
import { SortIcon, SortOrder, TableLocale } from './interface';
import Tooltip from '../tooltip';
import isEnterPress from '@douyinfe/semi-foundation/utils/isEnterPress';
import { getNextSortOrder } from './utils';
import LocaleConsumer from '../locale/localeConsumer';

export interface ColumnSorterProps {
className?: string;
Expand All @@ -16,7 +19,8 @@ export interface ColumnSorterProps {
prefixCls?: string;
sortOrder?: SortOrder;
title?: React.ReactNode;
sortIcon?: SortIcon
sortIcon?: SortIcon;
showTooltip?: boolean
}

export default class ColumnSorter extends PureComponent<ColumnSorterProps> {
Expand All @@ -27,16 +31,18 @@ export default class ColumnSorter extends PureComponent<ColumnSorterProps> {
prefixCls: PropTypes.string,
sortOrder: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
sortIcon: PropTypes.func,
showTooltip: PropTypes.bool,
};

static defaultProps = {
prefixCls: cssClasses.PREFIX,
onClick: noop,
sortOrder: false,
showTooltip: false
};

render() {
const { prefixCls, onClick, sortOrder, style, title, sortIcon } = this.props;
const { prefixCls, onClick, sortOrder, style, title, sortIcon, showTooltip } = this.props;

const iconBtnSize = 'default';

Expand All @@ -60,16 +66,27 @@ export default class ColumnSorter extends PureComponent<ColumnSorterProps> {
if (typeof sortIcon === 'function') {
return sortIcon({ sortOrder });
} else {
return (
<div style={style} className={`${prefixCls}-column-sorter`}>
<span className={`${upCls}`}>
<IconCaretup size={iconBtnSize} />
</span>
<span className={`${downCls}`}>
<IconCaretdown size={iconBtnSize} />
</span>
</div>
);
const node = (<div style={style} className={`${prefixCls}-column-sorter`}>
<span className={`${upCls}`}>
<IconCaretup size={iconBtnSize} />
</span>
<span className={`${downCls}`}>
<IconCaretdown size={iconBtnSize} />
</span>
</div>);
if (showTooltip) {
let content = getNextSortOrder(sortOrder);
return (<LocaleConsumer
componentName="Table"
>
{(locale: TableLocale, localeCode: string) => (
<Tooltip content={locale[content]}>
{node}
</Tooltip>
)}
</LocaleConsumer>);
}
return node;
}
};

Expand Down
Loading

0 comments on commit 0f39595

Please sign in to comment.