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",
"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",
header: "Data Comp.",
cell: ({ getValue }: any) => {
filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => string }) => {
const value = getValue();
return new Date(value).toLocaleDateString('pt-BR');
}
@ -122,7 +123,8 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
{
accessorKey: "data_vencimento",
header: "Data Venc.",
cell: ({ getValue }: any) => {
filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => string }) => {
const value = getValue();
return new Date(value).toLocaleDateString('pt-BR');
}
@ -130,20 +132,22 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
{
accessorKey: "data_caixa",
header: "Data Caixa",
cell: ({ getValue }: any) => {
filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => string }) => {
const value = getValue();
return new Date(value).toLocaleDateString('pt-BR');
}
},
{ accessorKey: "codigo_fornecedor", header: "Cód. Fornec." },
{ accessorKey: "nome_fornecedor", header: "Fornecedor" },
{ accessorKey: "codigo_centrocusto", header: "Cód. Centro" },
{ accessorKey: "codigo_conta", header: "Cód. Conta" },
{ accessorKey: "conta", header: "Conta" },
{ accessorKey: "codigo_fornecedor", header: "Cód. Fornec.", filterFn: "advancedText" },
{ accessorKey: "nome_fornecedor", header: "Fornecedor", filterFn: "advancedText" },
{ accessorKey: "codigo_centrocusto", header: "Cód. Centro", filterFn: "advancedText" },
{ accessorKey: "codigo_conta", header: "Cód. Conta", filterFn: "advancedText" },
{ accessorKey: "conta", header: "Conta", filterFn: "advancedText" },
{
accessorKey: "valor",
header: "Valor",
cell: ({ getValue }: any) => {
filterFn: "advancedText",
cell: ({ getValue }: { getValue: () => number }) => {
const value = getValue();
const formatted = new Intl.NumberFormat('pt-BR', {
style: 'currency',
@ -157,9 +161,9 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
);
}
},
{ accessorKey: "historico", header: "Histórico" },
{ accessorKey: "historico2", header: "Histórico 2" },
{ accessorKey: "recnum", header: "Recnum" },
{ accessorKey: "historico", header: "Histórico", filterFn: "advancedText" },
{ accessorKey: "historico2", header: "Histórico 2", filterFn: "advancedText" },
{ accessorKey: "recnum", header: "Recnum", filterFn: "advancedText" },
],
[]
);
@ -228,9 +232,15 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
}, []);
const applyFilters = () => {
const filters = conditions
.filter((c) => c.column && (c.operator === "empty" || c.operator === "notEmpty" || (c.value ?? "") !== ""))
.map((c) => ({ id: c.column, value: { operator: c.operator, value: c.value } }));
const validConditions = conditions.filter((c) =>
c.column && (c.operator === "empty" || c.operator === "notEmpty" || (c.value ?? "") !== "")
);
const filters = validConditions.map((c) => ({
id: c.column,
value: { operator: c.operator, value: c.value }
}));
setColumnFilters(filters);
setOpen(false);
};
@ -343,9 +353,9 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
<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"}`}
>
{table.getHeaderGroups().map((hg: any) => (
{table.getHeaderGroups().map((hg) => (
<tr key={hg.id}>
{hg.headers.map((header: any) => {
{hg.headers.map((header) => {
const sorted = header.column.getIsSorted();
return (
<th
@ -406,7 +416,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
</td>
</tr>
) : (
virtualRows.map((virtualRow: any) => {
virtualRows.map((virtualRow) => {
const row = table.getRowModel().rows[virtualRow.index];
return (
<tr
@ -422,7 +432,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
tableLayout: "fixed",
}}
>
{row.getVisibleCells().map((cell: any, cellIndex: number) => (
{row.getVisibleCells().map((cell, cellIndex) => (
<td
key={cell.id}
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' : ''
}`}
title={cell.getValue()}
title={String(cell.getValue())}
>
<div className="truncate">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
@ -502,7 +512,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
<SelectValue placeholder="Selecione a coluna" />
</SelectTrigger>
<SelectContent>
{columns.map((col: any) => (
{columns.map((col) => (
<SelectItem key={col.accessorKey} value={col.accessorKey}>
{col.header}
</SelectItem>