From e5fa6bb6ea21aaa6839220a4139a9b04c7184249 Mon Sep 17 00:00:00 2001 From: "pramod.mahajan" Date: Mon, 8 Dec 2025 00:47:46 +0530 Subject: [PATCH] partially added advance filter --- .../collections/PmGridCollection.jsx | 70 ++--- src/services/pmsGrid/PmsGrid.jsx | 24 +- src/services/pmsGrid/PmsHeaderOption.jsx | 282 ++++++++++-------- src/services/pmsGrid/useGridCore.js | 25 +- 4 files changed, 227 insertions(+), 174 deletions(-) diff --git a/src/components/collections/PmGridCollection.jsx b/src/components/collections/PmGridCollection.jsx index a558a81f..4f9dbc46 100644 --- a/src/components/collections/PmGridCollection.jsx +++ b/src/components/collections/PmGridCollection.jsx @@ -81,40 +81,42 @@ const PmGridCollection = ({ selectedProject, fromDate, toDate, isPending }) => { }; return ( - console.log("Edit", row), - }, - { - label: "Delete", - icon: "bx-trash text-danger", - onClick: (row) => console.log("Delete", row), - }, - - ] - }} - /> + console.log("Edit", row), + }, + { + label: "Delete", + icon: "bx-trash text-danger", + onClick: (row) => console.log("Delete", row), + }, + ], + }} +/> + ); }; diff --git a/src/services/pmsGrid/PmsGrid.jsx b/src/services/pmsGrid/PmsGrid.jsx index df258e78..ba51e16e 100644 --- a/src/services/pmsGrid/PmsGrid.jsx +++ b/src/services/pmsGrid/PmsGrid.jsx @@ -57,6 +57,8 @@ export default function PmsGrid({ expanded, toggleExpand, setColState, + onAdvanceFilters, + setAdanceFilter, } = grid; // --- Pin / Unpin helpers --- @@ -254,14 +256,10 @@ export default function PmsGrid({ style={{ position: "sticky", top: 0, zIndex: 10 }} > - {features.IsNumbering && ( - - # - - )} + {features.IsNumbering && #} {features.expand && ( - + )} {features.selection && ( @@ -284,7 +282,7 @@ export default function PmsGrid({ /> )} - + {visibleColumns.map((col) => { const style = { minWidth: col.width || 120, @@ -333,10 +331,12 @@ export default function PmsGrid({
{features.pinning && ( pinColumn(col.key, "left")} onPinRight={() => pinColumn(col.key, "right")} onUnpin={() => unpinColumn(col.key)} + onAdvancedFilter={setAdanceFilter} /> )} {features.resizing && ( @@ -378,9 +378,9 @@ export default function PmsGrid({ )} {!loading && groupBy && groupedRows && groupedRows.length > 0 - ? groupedRows.map((g,indG) => ( + ? groupedRows.map((g, indG) => ( - + - {g.items.map((row,indG) => renderRow(row,indG))} + {g.items.map((row, indG) => renderRow(row, indG))} )) : currentRows.map((row, ind) => renderRow(row, ind))} @@ -450,7 +450,7 @@ export default function PmsGrid({ {ind + 1} )} - {/* Expand toggle next to selection */} + {/* Expand toggle next to selection */} {features.expand && ( +import { useState } from "react"; -import { useEffect } from "react"; +const OPERATORS = { + number: [ + { key: "eq", label: "Equals" }, + { key: "neq", label: "Not Equal" }, + { key: "gt", label: "Greater Than" }, + { key: "gte", label: "Greater or Equal" }, + { key: "less than", label: "Less Than" }, + { key: "lte", label: "Less or Equal" }, + { key: "between", label: "Between" }, + ], + text: [ + { key: "contains", label: "Contains" }, + { key: "starts", label: "Starts With" }, + { key: "ends", label: "Ends With" }, + { key: "eq", label: "Equals" }, + ], + date: [ + { key: "before", label: "Before" }, + { key: "after", label: "After" }, + { key: "between", label: "Between" }, + ], +}; -//
    -//
  • -// -//
  • -//
  • -// -//
  • -// {pinned && ( -// <> -//
  • -//
    -//
  • -//
  • -// -//
  • -// -// )} -//
-//
-// ); -// }; -// export default PmsHeaderOption; -const PmsHeaderOption = ({ pinned, onPinLeft, onPinRight, onUnpin }) => { - const toggleSubmenu = (e) => { - e.stopPropagation(); +// ----------- FILTER UI COMPONENT ---------- +function AdvanceFilter({ type = "number", onApply, onClear }) { + const [operator, setOperator] = useState(""); + const [value1, setValue1] = useState(""); + const [value2, setValue2] = useState(""); - const currentSubMenu = e.currentTarget.nextElementSibling; - if (!currentSubMenu) return; + const ops = OPERATORS[type]; - const allSubMenus = document.querySelectorAll( - ".dropdown-submenu > .dropdown-menu" - ); + const apply = () => { + if (!operator) return; - allSubMenus.forEach((menu) => { - if (menu !== currentSubMenu) { - menu.classList.remove("show"); - } - }); - - currentSubMenu.classList.toggle("show"); + if (operator === "between") { + onApply({ + operator, + from: value1, + to: value2, + }); + } else { + onApply({ + operator, + value: value1, + }); + } }; - useEffect(() => { - const handleOutsideClick = () => { - const allSubMenus = document.querySelectorAll( - ".dropdown-submenu > .dropdown-menu" - ); + return ( +
e.stopPropagation()} // prevent closing menu + style={{ width: 240 }} + > + {/* Operator Dropdown */} +
+ + +
- allSubMenus.forEach((menu) => { - menu.classList.remove("show"); - }); - }; + {/* Values */} + {operator && ( +
+ - document.addEventListener("click", handleOutsideClick); + {operator !== "between" ? ( + setValue1(e.target.value)} + /> + ) : ( +
+ setValue1(e.target.value)} + /> - return () => { - document.removeEventListener("click", handleOutsideClick); - }; - }, []); + setValue2(e.target.value)} + /> +
+ )} +
+ )} + + {/* Buttons */} +
+ + +
+
+ ); +} + +// -------- HEADER OPTION --------------- +const PmsHeaderOption = ({ + column, + pinned, + onPinLeft, + onPinRight, + onUnpin, + onAdvancedFilter, +}) => { + const [openMenu, setOpenMenu] = useState(null); + + const toggleMenu = (key, e) => { + e.stopPropagation(); + setOpenMenu((prev) => (prev === key ? null : key)); + }; return (
-
    +
      + {/* ADVANCED FILTER */}
    • -
        -
      • - -
      • - -
      • - +
          +
        • + onAdvancedFilter({...f,column})} + onClear={() => onAdvancedFilter(null)} + />
      • + {/* PIN COLUMN */}
      • -
          +
          • -
          • +
          • -
          • +