Skip to content

Commit

Permalink
feat(table): table filter add match-pinyin (#2210)
Browse files Browse the repository at this point in the history
Co-authored-by: vermilionAnd <zhujiahong@growingio.com>
  • Loading branch information
zhuzilv and vermilionAnd committed Nov 6, 2023
1 parent 2e3cdbb commit b0ac53f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/table/FilterPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useContext, useEffect } from 'react';
import { invoke, isFunction, isObject } from 'lodash';
import { useLocale } from '@gio-design/utils';
import pinyinMatch from 'pinyin-match';
import Button from '../button';
import Popover from '../popover';
import FilterList from './FilterList';
Expand All @@ -25,6 +26,13 @@ interface FilterPopoverProps {
singleSelectDefaultValue?: string;
}

function isContain(target = '', source = ''): boolean {
if (source === '') {
return true;
}
return !!pinyinMatch.match(target, source);
}

const FilterPopover = (props: FilterPopoverProps): React.ReactElement => {
const locale = useLocale('Table');
const { clearText, okText, searchText }: typeof defaultLocale = {
Expand Down Expand Up @@ -116,9 +124,9 @@ const FilterPopover = (props: FilterPopoverProps): React.ReactElement => {
dataSource={filters
.filter((item) => {
if (isObject(item)) {
return item.label.includes(searchValue);
return isContain(item.label, searchValue);
}
return item.toString().includes(searchValue);
return isContain(item.toString(), searchValue);
})
.map((item) => {
if (isObject(item)) {
Expand Down

0 comments on commit b0ac53f

Please sign in to comment.