1

I want to filter the column in ag grid for date and time together ag grid doesnot support date and time filter together.

I tried using only time but the filtering is not happening in ag grid it is not triggering the filter for ag grid.

The issue is isFilterActive() is not getting triggered

const TimeFilter = forwardRef((props, ref) => {
  const [filterType, setFilterType] = useState('equals');
  const [timeFrom, setTimeFrom] = useState('');
  const [timeTo, setTimeTo] = useState('');

  const parseTime = (val) => {
    if (!val) return null;
    const [h, m] = val.split(':').map(Number);
    return h * 60 + m;
  };

  useImperativeHandle(ref, () => ({
    isFilterActive() {
      return filterType === 'inRange'
        ? !!timeFrom && !!timeTo
        : !!timeFrom;
    },

  

  useEffect(() => {
    props.filterChangedCallback?.();
  }, [filterType, timeFrom, timeTo]);

  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
      <select value={filterType} onChange={(e) => setFilterType(e.target.value)}>
        <option value="equals">Equals</option>
        <option value="lessThan">Before</option>
        <option value="greaterThan">After</option>
        <option value="inRange">In Range</option>
      </select>

      <input
        type="time"
        value={timeFrom}
        onChange={(e) => setTimeFrom(e.target.value)}
      />

      {filterType === 'inRange' && (
        <input
          type="time"
          value={timeTo}
          onChange={(e) => setTimeTo(e.target.value)}
        />
      )}
    </div>
  );
});

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.