"use client"; import BABox from "./BABox"; import { BACheckbox, BALoader, BAPera } from "."; import { DeleteOutlined } from "@ant-design/icons"; import { useState } from "react"; import { theme } from "antd"; type propsType = { datasourse: any[]; cols: { key: string; label: string; displayField?: (data: any, i: number) => any; HeaderField?: any; }[]; loading?: boolean; onChange?: any; displayField?: any; closeModal?: any; onRowClick?: any; allowMultiple?: boolean; setDataSource?: any; className?: string; allowSearch?: boolean; allowDelete?: boolean; onDelete?: (index: number) => void; colSearchObj?: any, handleSearch?: (pgObj?: any, SearchObj?: any) => void; }; export default function BAGrid(props: propsType) { const { datasourse, cols, loading, displayField, onRowClick, allowMultiple, setDataSource, allowSearch, handleSearch, colSearchObj = {}, allowDelete, onDelete } = props; const { token }: any = theme.useToken(); const [isAllSelected, setIsAllSelected] = useState(false); const [gridSearchObj, setGridSearchObj] = useState(colSearchObj); const onRowSelect = (data: any, i: number, checked: boolean) => { if (datasourse.length) { const listData = [...datasourse]; listData[i] = { ...data, isSelected: checked }; const selectionRemaining = listData.find((el) => !el.isSelected); if (!selectionRemaining) setIsAllSelected(true); else setIsAllSelected(false); setDataSource(listData); } }; const onSelectAll = (checked: boolean) => { setIsAllSelected(checked); const listData = [...datasourse]; listData.map((item) => ({ ...item, isSelected: checked })); setDataSource(listData.map((item) => ({ ...item, isSelected: checked }))); }; const indeterminate = !isAllSelected && datasourse?.find((el) => el.isSelected); return ( {allowSearch && } {allowMultiple && ( )} {allowDelete && } {cols.map((col: any, index: number) => ( ))} {datasourse && datasourse.length > 0 ? ( datasourse.map((row: any, rowIndex: number) => ( (onRowClick ? onRowClick(rowIndex, row) : {})} > {allowSearch && } {allowMultiple && ( )} {allowDelete && onDelete && } {cols.map((col: any, colIndex: number) => ( ))} )) ) : loading ? ( ) : ( )}
onSelectAll(e.target.checked)} checked={isAllSelected || false} isMultiple={indeterminate} /> Action {col.label}
onRowSelect(row, rowIndex, e.target.checked) } /> onDelete(rowIndex)} /> {col.displayField ? col.displayField(row, rowIndex) : row[col.key]} {col.HeaderField ? col.HeaderField(rowIndex) : ""}
No Data Found
); }