import React, { useState, useEffect } from 'react'; import { classNames } from 'primereact/utils'; import { FilterMatchMode, FilterOperator } from 'primereact/api'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; import { Dropdown } from 'primereact/dropdown'; import { InputNumber } from 'primereact/inputnumber'; import { Button } from 'primereact/button'; import { ProgressBar } from 'primereact/progressbar'; import { Calendar } from 'primereact/calendar'; import { MultiSelect } from 'primereact/multiselect'; import { Slider } from 'primereact/slider'; import { TriStateCheckbox } from 'primereact/tristatecheckbox'; import { ToggleButton } from 'primereact/togglebutton'; import { Rating } from 'primereact/rating'; import { CustomerService } from '../service/CustomerService'; import { ProductService } from '../service/ProductService'; const TableDemo = () => { const [customers1, setCustomers1] = useState(null); const [customers2, setCustomers2] = useState([]); const [customers3, setCustomers3] = useState([]); const [filters1, setFilters1] = useState(null); const [loading1, setLoading1] = useState(true); const [loading2, setLoading2] = useState(true); const [idFrozen, setIdFrozen] = useState(false); const [products, setProducts] = useState([]); const [expandedRows, setExpandedRows] = useState(null); const representatives = [ { name: 'Amy Elsner', image: 'amyelsner.png' }, { name: 'Anna Fali', image: 'annafali.png' }, { name: 'Asiya Javayant', image: 'asiyajavayant.png' }, { name: 'Bernardo Dominic', image: 'bernardodominic.png' }, { name: 'Elwin Sharvill', image: 'elwinsharvill.png' }, { name: 'Ioni Bowcher', image: 'ionibowcher.png' }, { name: 'Ivan Magalhaes', image: 'ivanmagalhaes.png' }, { name: 'Onyama Limba', image: 'onyamalimba.png' }, { name: 'Stephen Shaw', image: 'stephenshaw.png' }, { name: 'XuXue Feng', image: 'xuxuefeng.png' }, ]; const statuses = [ 'unqualified', 'qualified', 'new', 'negotiation', 'renewal', 'proposal', ]; const customerService = new CustomerService(); const productService = new ProductService(); useEffect(() => { setLoading2(true); customerService.getCustomersLarge().then((data) => { setCustomers1(getCustomers(data)); setLoading1(false); }); customerService.getCustomersLarge().then((data) => { setCustomers2(getCustomers(data)); setLoading2(false); }); customerService.getCustomersMedium().then((data) => setCustomers3(data)); productService .getProductsWithOrdersSmall() .then((data) => setProducts(data)); initFilters1(); }, []); // eslint-disable-line react-hooks/exhaustive-deps const balanceTemplate = (rowData) => { return {formatCurrency(rowData.balance)}; }; const getCustomers = (data) => { return [...(data || [])].map((d) => { d.date = new Date(d.date); return d; }); }; const formatDate = (value) => { return value.toLocaleDateString('en-US', { day: '2-digit', month: '2-digit', year: 'numeric', }); }; const formatCurrency = (value) => { return value.toLocaleString('en-US', { style: 'currency', currency: 'USD', }); }; const initFilters1 = () => { setFilters1({ global: { value: null, matchMode: FilterMatchMode.CONTAINS }, name: { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }], }, 'country.name': { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }], }, representative: { value: null, matchMode: FilterMatchMode.IN }, date: { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }], }, balance: { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.EQUALS }], }, status: { operator: FilterOperator.OR, constraints: [{ value: null, matchMode: FilterMatchMode.EQUALS }], }, activity: { value: null, matchMode: FilterMatchMode.BETWEEN }, verified: { value: null, matchMode: FilterMatchMode.EQUALS }, }); }; const countryBodyTemplate = (rowData) => { return ( flag {rowData.country.name} ); }; const filterClearTemplate = (options) => { return ( ); }; const filterApplyTemplate = (options) => { return ( ); }; const representativeBodyTemplate = (rowData) => { const representative = rowData.representative; return ( {representative.name} (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png') } width={32} style={{ verticalAlign: 'middle' }} /> {representative.name} ); }; const representativeFilterTemplate = (options) => { return ( <>
Agent Picker
options.filterCallback(e.value)} optionLabel="name" placeholder="Any" className="p-column-filter" /> ); }; const representativesItemTemplate = (option) => { return (
{option.name} {option.name}
); }; const dateBodyTemplate = (rowData) => { return formatDate(rowData.date); }; const dateFilterTemplate = (options) => { return ( options.filterCallback(e.value, options.index)} dateFormat="mm/dd/yy" placeholder="mm/dd/yyyy" mask="99/99/9999" /> ); }; const balanceBodyTemplate = (rowData) => { return formatCurrency(rowData.balance); }; const balanceFilterTemplate = (options) => { return ( options.filterCallback(e.value, options.index)} mode="currency" currency="USD" locale="en-US" /> ); }; const statusBodyTemplate = (rowData) => { return ( {rowData.status} ); }; const statusFilterTemplate = (options) => { return ( options.filterCallback(e.value, options.index)} itemTemplate={statusItemTemplate} placeholder="Select a Status" className="p-column-filter" showClear /> ); }; const statusItemTemplate = (option) => { return {option}; }; const activityBodyTemplate = (rowData) => { return ( ); }; const activityFilterTemplate = (options) => { return ( options.filterCallback(e.value)} range className="m-3" >
{options.value ? options.value[0] : 0} {options.value ? options.value[1] : 100}
); }; const verifiedBodyTemplate = (rowData) => { return ( ); }; const verifiedFilterTemplate = (options) => { return ( options.filterCallback(e.value)} /> ); }; const expandAll = () => { let _expandedRows = {}; products.forEach((p) => (_expandedRows[`${p.id}`] = true)); setExpandedRows(_expandedRows); }; const collapseAll = () => { setExpandedRows(null); }; const amountBodyTemplate = (rowData) => { return formatCurrency(rowData.amount); }; const statusOrderBodyTemplate = (rowData) => { return ( {rowData.status} ); }; const searchBodyTemplate = () => { return