devexpress-reporting-react
Version:
DevExpress Reporting React provides the capability to develop a reporting application to create and customize reports.
25 lines (24 loc) • 1.19 kB
JavaScript
import React from 'react';
import TreelistGroup from './TreelistGroup';
import { initTreeListBinding } from '@devexpress/analytics-core/widgets/treelist/_binding';
import { ViewModelChangedEvent } from '@devexpress/analytics-core/serializer/native/viewModels/viewModelGenerator';
const Treelist = ({ options, ...delegatedProps }) => {
const htmlRef = React.useRef();
const [viewModel, setViewModel] = React.useState();
React.useEffect(() => {
if (!htmlRef.current)
return () => { };
const disposables = [];
disposables.push(initTreeListBinding({
values: options,
element: htmlRef.current,
createChildContext: (vm) => {
disposables.push(vm?._viewModelEvents?.on(ViewModelChangedEvent, () => setViewModel({ ...vm })));
setViewModel({ ...vm });
},
}));
return () => disposables.forEach(disposable => disposable && disposable());
}, [options, htmlRef.current]);
return React.createElement("div", { ref: htmlRef, ...delegatedProps }, viewModel ? React.createElement(TreelistGroup, { data: viewModel }) : null);
};
export default Treelist;