Uecko_ERP/modules/customers/src/web/components/customers-list-grid.tsx

71 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-08-11 17:49:52 +00:00
import { useState } from "react";
import { AG_GRID_LOCALE_ES } from "@ag-grid-community/locale";
// Grid
import type { ColDef, GridOptions, ValueFormatterParams } from "ag-grid-community";
import { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
ModuleRegistry.registerModules([AllCommunityModule]);
// Core CSS
import { AgGridReact } from "ag-grid-react";
import { useCustomersQuery } from "../hooks";
import { useTranslation } from "../i18n";
import { CustomerStatusBadge } from "./customer-status-badge";
// Create new GridExample component
export const CustomersListGrid = () => {
const { t } = useTranslation();
const { data, isLoading, isPending, isError, error } = useCustomersQuery({});
// Column Definitions: Defines & controls grid columns.
const [colDefs] = useState<ColDef[]>([
{
2025-08-23 11:57:48 +00:00
field: "status",
headerName: t("pages.list.grid_columns.status"),
2025-08-11 17:49:52 +00:00
cellRenderer: (params: ValueFormatterParams) => {
return <CustomerStatusBadge status={params.value} />;
},
},
2025-08-23 11:57:48 +00:00
{ field: "name", headerName: t("pages.list.grid_columns.name") },
{ field: "trade_name", headerName: t("pages.list.grid_columns.trade_name") },
2025-08-11 17:49:52 +00:00
{
2025-08-23 11:57:48 +00:00
field: "email",
headerName: t("pages.list.grid_columns.email"),
2025-08-11 17:49:52 +00:00
},
]);
const gridOptions: GridOptions = {
columnDefs: colDefs,
defaultColDef: {
editable: true,
flex: 1,
minWidth: 100,
filter: false,
sortable: false,
resizable: true,
},
pagination: true,
paginationPageSize: 10,
paginationPageSizeSelector: [10, 20, 30, 50],
localeText: AG_GRID_LOCALE_ES,
rowSelection: { mode: "multiRow" },
};
// Container: Defines the grid's theme & dimensions.
return (
<div
className='ag-theme-alpine'
style={{
height: "100%",
width: "100%",
}}
>
<AgGridReact rowData={data?.items ?? []} loading={isLoading || isPending} {...gridOptions} />
</div>
);
};