antd#TreeDataNode TypeScript Examples
The following examples show how to use
antd#TreeDataNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.tsx From datart with Apache License 2.0 | 7 votes |
export function buildAntdTreeNodeModel<T extends TreeDataNode & { value: any }>(
ancestors: string[] = [],
nodeName: string,
children?: T[],
isLeaf?: boolean,
): T {
const TREE_HIERARCHY_SEPERATOR = String.fromCharCode(0);
const fullNames = ancestors.concat(nodeName);
return {
key: fullNames.join(TREE_HIERARCHY_SEPERATOR),
title: nodeName,
value: fullNames,
children,
isLeaf,
} as any;
}
Example #2
Source File: utils.ts From datart with Apache License 2.0 | 7 votes |
export function getExpandedKeys<T extends TreeDataNode>(nodes: T[]) {
return nodes.reduce<string[]>((keys, { key, children }) => {
if (Array.isArray(children) && children.length) {
return keys
.concat(key as string)
.concat(children ? getExpandedKeys(children) : []);
}
return keys;
}, []);
}
Example #3
Source File: useSearchAndExpand.ts From datart with Apache License 2.0 | 6 votes |
export function useSearchAndExpand<T extends TreeDataNode>(
dataSource: T[] | undefined,
filterFunc: (keywords: string, data: T) => boolean,
wait: number = DEFAULT_DEBOUNCE_WAIT,
filterLeaf: boolean = false,
) {
const [expandedRowKeys, setExpandedRowKeys] = useState<string[]>([]);
const { keywords, filteredData, debouncedSearch } = useDebouncedSearch(
dataSource,
filterFunc,
wait,
filterLeaf,
);
const filteredExpandedRowKeys = useMemo(
() =>
filteredData && keywords.trim() ? getExpandedKeys(filteredData) : [],
[keywords, filteredData],
);
const onExpand = useCallback(expandedRowKeys => {
setExpandedRowKeys(expandedRowKeys);
}, []);
return {
keywords,
filteredData,
expandedRowKeys:
filteredExpandedRowKeys.length > 0
? filteredExpandedRowKeys
: expandedRowKeys,
onExpand,
debouncedSearch,
setExpandedRowKeys,
};
}