react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

how to use e.stopPropagation() in react bootstraap table column?

Open kyou-ennbunn opened this issue 5 years ago • 1 comments

👍

Originally posted by @AllenFang in https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/1042#issuecomment-518294262

kyou-ennbunn avatar Sep 07 '20 16:09 kyou-ennbunn

I figured out the case for myself:

After e.stopPropagation() for un-used columns, bind customised action for column

  const [showConfirmModal, setShowConfirmModal] = useState(false);
  // store targeted Id for API purpose
  const activeId = useRef(null);
  // UI purpose for calculate modal postion
  const [activeIndex, setActiveIndex] = useState(0);

  const rowEvents = {
    onClick: (e, row, rowIndex) => {
      setActiveIndex(rowIndex);
      setShowConfirmModal(true);
      activeId.current = row.id;
    },
  };

UI

  {showConfirmModal ? (
    <div
      className="delete-confirm-modal"
      style={{
        position: 'absolute',
        // based on rowIndex and rowHeight: 50px
        top: `${(activeIndex + 1) * 50}px`,
        right: '-90px',
      }}
    >
      Confirm delete?
      <div>
        <button
          onClick={() => {
            setShowConfirmModal(false);
          }}
        >
          Cancel
        </button>
        <button
          onClick={() => {
            // use for API
            console.log('activeId', activeId.current);
          }}
        >
          Confirm
        </button>
      </div>
    </div>
  ) : null}

congweibai avatar Oct 15 '24 05:10 congweibai