fix: filtro

This commit is contained in:
Alessandro Gonçaalves 2025-10-20 13:03:14 -03:00
parent 7758ad5abe
commit 1de1031fbc
2 changed files with 56 additions and 44 deletions

View File

@ -1,6 +1,8 @@
{ {
"extends": "next/core-web-vitals", "extends": "next/core-web-vitals",
"rules": { "rules": {
"@typescript-eslint/no-explicit-any": "off" "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-object-type": "off"
} }
} }

View File

@ -114,7 +114,8 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
{ {
accessorKey: "data_competencia", accessorKey: "data_competencia",
header: "Data Comp.", header: "Data Comp.",
cell: ({ getValue }: any) => { filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => string }) => {
const value = getValue(); const value = getValue();
return new Date(value).toLocaleDateString('pt-BR'); return new Date(value).toLocaleDateString('pt-BR');
} }
@ -122,7 +123,8 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
{ {
accessorKey: "data_vencimento", accessorKey: "data_vencimento",
header: "Data Venc.", header: "Data Venc.",
cell: ({ getValue }: any) => { filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => string }) => {
const value = getValue(); const value = getValue();
return new Date(value).toLocaleDateString('pt-BR'); return new Date(value).toLocaleDateString('pt-BR');
} }
@ -130,20 +132,22 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
{ {
accessorKey: "data_caixa", accessorKey: "data_caixa",
header: "Data Caixa", header: "Data Caixa",
cell: ({ getValue }: any) => { filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => string }) => {
const value = getValue(); const value = getValue();
return new Date(value).toLocaleDateString('pt-BR'); return new Date(value).toLocaleDateString('pt-BR');
} }
}, },
{ accessorKey: "codigo_fornecedor", header: "Cód. Fornec." }, { accessorKey: "codigo_fornecedor", header: "Cód. Fornec.", filterFn: "advancedText" },
{ accessorKey: "nome_fornecedor", header: "Fornecedor" }, { accessorKey: "nome_fornecedor", header: "Fornecedor", filterFn: "advancedText" },
{ accessorKey: "codigo_centrocusto", header: "Cód. Centro" }, { accessorKey: "codigo_centrocusto", header: "Cód. Centro", filterFn: "advancedText" },
{ accessorKey: "codigo_conta", header: "Cód. Conta" }, { accessorKey: "codigo_conta", header: "Cód. Conta", filterFn: "advancedText" },
{ accessorKey: "conta", header: "Conta" }, { accessorKey: "conta", header: "Conta", filterFn: "advancedText" },
{ {
accessorKey: "valor", accessorKey: "valor",
header: "Valor", header: "Valor",
cell: ({ getValue }: any) => { filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => number }) => {
const value = getValue(); const value = getValue();
const formatted = new Intl.NumberFormat('pt-BR', { const formatted = new Intl.NumberFormat('pt-BR', {
style: 'currency', style: 'currency',
@ -157,9 +161,9 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
); );
} }
}, },
{ accessorKey: "historico", header: "Histórico" }, { accessorKey: "historico", header: "Histórico", filterFn: "advancedText" },
{ accessorKey: "historico2", header: "Histórico 2" }, { accessorKey: "historico2", header: "Histórico 2", filterFn: "advancedText" },
{ accessorKey: "recnum", header: "Recnum" }, { accessorKey: "recnum", header: "Recnum", filterFn: "advancedText" },
], ],
[] []
); );
@ -228,9 +232,15 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
}, []); }, []);
const applyFilters = () => { const applyFilters = () => {
const filters = conditions const validConditions = conditions.filter((c) =>
.filter((c) => c.column && (c.operator === "empty" || c.operator === "notEmpty" || (c.value ?? "") !== "")) c.column && (c.operator === "empty" || c.operator === "notEmpty" || (c.value ?? "") !== "")
.map((c) => ({ id: c.column, value: { operator: c.operator, value: c.value } })); );
const filters = validConditions.map((c) => ({
id: c.column,
value: { operator: c.operator, value: c.value }
}));
setColumnFilters(filters); setColumnFilters(filters);
setOpen(false); setOpen(false);
}; };
@ -343,9 +353,9 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
<thead <thead
className={`bg-gradient-to-r from-blue-50 to-indigo-50 sticky top-0 z-20 transition-all duration-200 ${isScrolled ? "shadow-lg" : "shadow-sm"}`} className={`bg-gradient-to-r from-blue-50 to-indigo-50 sticky top-0 z-20 transition-all duration-200 ${isScrolled ? "shadow-lg" : "shadow-sm"}`}
> >
{table.getHeaderGroups().map((hg: any) => ( {table.getHeaderGroups().map((hg) => (
<tr key={hg.id}> <tr key={hg.id}>
{hg.headers.map((header: any) => { {hg.headers.map((header) => {
const sorted = header.column.getIsSorted(); const sorted = header.column.getIsSorted();
return ( return (
<th <th
@ -406,7 +416,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
</td> </td>
</tr> </tr>
) : ( ) : (
virtualRows.map((virtualRow: any) => { virtualRows.map((virtualRow) => {
const row = table.getRowModel().rows[virtualRow.index]; const row = table.getRowModel().rows[virtualRow.index];
return ( return (
<tr <tr
@ -422,7 +432,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
tableLayout: "fixed", tableLayout: "fixed",
}} }}
> >
{row.getVisibleCells().map((cell: any, cellIndex: number) => ( {row.getVisibleCells().map((cell, cellIndex) => (
<td <td
key={cell.id} key={cell.id}
className={`px-4 py-3 text-sm whitespace-nowrap overflow-hidden ${ className={`px-4 py-3 text-sm whitespace-nowrap overflow-hidden ${
@ -430,7 +440,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
} ${ } ${
cell.column.id === 'valor' ? 'text-right font-semibold' : '' cell.column.id === 'valor' ? 'text-right font-semibold' : ''
}`} }`}
title={cell.getValue()} title={String(cell.getValue())}
> >
<div className="truncate"> <div className="truncate">
{flexRender(cell.column.columnDef.cell, cell.getContext())} {flexRender(cell.column.columnDef.cell, cell.getContext())}
@ -502,7 +512,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
<SelectValue placeholder="Selecione a coluna" /> <SelectValue placeholder="Selecione a coluna" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{columns.map((col: any) => ( {columns.map((col) => (
<SelectItem key={col.accessorKey} value={col.accessorKey}> <SelectItem key={col.accessorKey} value={col.accessorKey}>
{col.header} {col.header}
</SelectItem> </SelectItem>