Focus on FloatingObject cleared selection ranges.

Posted by: zhoubing.yang on 13 May 2022, 5:21 am EST

  • Posted 13 May 2022, 5:21 am EST

    We have a custom floating object, every time when we click or focus on the floating object the selection range highlighted on the original data is gone.
    Is there a way to have the selection range remain where it was?
    Thanks
  • Replied 13 May 2022, 5:26 am EST

    I will like to add more detail to the scenario what I just describe above.
    It's pretty easy to handle the case when user click on the floating object for the first time as we can handle it through FloatingObjectChanged event, but it is tricky when user tried to click on the floating object again after it's already focused.
  • Replied 15 May 2022, 6:25 pm EST

    Hi,

    This is by design to match the excel behavior. However, to prevent this you handled the mouse down and mouse up event and update the selection accordingly. Please refer to the following code snippet and attached sample that explains the same.


    spread.getHost().addEventListener(
    "mousedown",
    function (e) {
    var y = e.pageY - this.offsetTop;
    var x = e.pageX - this.offsetLeft;

    var result = spread.hitTest(x, y);

    let floatingObject =
    result?.worksheetHitInfo?.floatingObjectHitInfo?.floatingObject;
    if (floatingObject) {
    console.log(floatingObject);
    objectInfo.isFloatingClick = true;
    objectInfo.selections = spread.getActiveSheet().getSelections();
    } else {
    console.log(floatingObject);
    objectInfo.isFloatingClick = false;
    objectInfo.selections = null;
    }
    },
    true
    );

    spread.getHost().addEventListener("mouseup", function (e) {
    var y = e.pageY - this.offsetTop;
    var x = e.pageX - this.offsetLeft;
    let sheet = spread.getActiveSheet();
    var result = spread.hitTest(x, y);

    let floatingObject =
    result?.worksheetHitInfo?.floatingObjectHitInfo?.floatingObject;
    if (floatingObject && objectInfo.selections) {
    objectInfo.selections.forEach(({ row, col, rowCount, colCount }) => {
    sheet.addSelection(row, col, rowCount, colCount);
    });
    }
    });


    sample: https://codesandbox.io/s/spread-js-starter-forked-1ykkhf?file=/src/index.js:871-2035

    References:
    HitTesting: https://www.grapecity.com/spreadjs/demos/features/workbook/hit-testing#demo_source_name

    Regards,
    Avinash
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels