I want to only visible columns, "Selection", "DragDrop", "DragFill".

Posted by: bungots on 2 October 2019, 2:13 am EST

  • Posted 2 October 2019, 2:13 am EST

    Hi.

    We has hidden columns.
    I want to do the following:
    Only visible columns,
    -Selection
    -DragDrop
    -DragFill

    There is also a case to copy and paste one line.
    Therefore I can't locked cels.

    Do you have any properties?
  • Replied 2 October 2019, 10:22 pm EST

    Hi,

    For DragDrop/DragFill operations you may handle DragDropBlock/DragFillBlock event and cancel the operation if the target range contains hidden column. Please refer to the following code snippet:
    spread.bind(GC.Spread.Sheets.Events.DragDropBlock, function(e, args) {
    let sheet = args.sheet;
    for (let c = args.toCol; c < args.toCol + args.colCount; c++) {
    if (!sheet.getColumnVisible(c)) {
    args.cancel = true;
    return;
    }
    }
    });

    spread.bind(GC.Spread.Sheets.Events.DragFillBlock, function(e, args) {
    let sheet = args.sheet,
    sel = args.fillRange;
    for (let c = sel.col; c < sel.col + sel.colCount; c++) {
    if (!sheet.getColumnVisible(c)) {
    args.cancel = true;
    return;
    }
    }
    });

    For preventing selections you have to mark cell as locked.

    Further, could you please explain some more about your use case?

    Regards
  • Replied 3 October 2019, 1:03 am EST

    Hi,
    I appreciate your help.

    The problem has been solved For DragDrop/DragFill operations.
    very easy-to-understand sample,
    thank you very match.

    The reason why we don't want to selection is un visible columns has contains control values.
    Therefore, Troubled if the value is erased.
    However. I don't want to lock the cell because I want to copy the row.



    Ctrl+Shift+end key:un visible column was not selected.
    but, In case of mouse drag , un visible column is selected.
    If we delete in that case, values for control is disappears.

    I solved the problem as follows.

    spread.bind(GC.Spread.Sheets.Events.SelectionChanged, function (sender, args) {
    let colIndexMaxShow = 8; // (example) visible column max index.
    let sheet = args.sheet;
    let selsBuff = sheet.getSelections();
    for (var i = 0; i < selsBuff.length; i++) {
    if (selsBuff[i].col + selsBuff[i].colCount > colIndexMaxShow) {
    var selsDef = sheet.getSelections();
    sheet.setSelection(selsBuff[i].row, selsBuff[i].col, selsBuff[i].rowCount, colIndexMaxShow - selsBuff[i].col);
    for (var k = 0; k < selsDef.length; k++) {
    if (i !== k) {
    sheet.addSelection(selsDef[k].row, selsDef[k].col, selsDef[k].rowCount, selsDef[k].colCount);
    }
    }
    }
    }
    });


    Please let me know if there is a better way.
  • Replied 3 October 2019, 5:08 pm EST

    >> I don't want to lock the cell because I want to copy the row.
    Locked cells could be copied like normal cells. Or do you need to allow paste for these hidden cells?
  • Replied 3 October 2019, 8:50 pm EST

    Hi,

    >>Locked cells could be copied like normal cells. Or do you need to allow paste for these hidden cells?

    Yes.

    When the cell is locked we can't paste copied content.
    As mentioned above un visible columns has contains control values.
    I want to copy that value as well.
  • Replied 8 October 2019, 4:24 pm EST

    Hi,

    I'm sorry but I'm unable to understand your use case, paste operation is inheritedly an edit operation, so if you do not want the user to change values why do you need to allow paste operation?
    Further, if you still need to prevent clear operation while allowing paste, then you may register a custom clear command on del key and prevent clear operation for hidden cells. Please refer to the following code snippet:
    var cm = spread.commandManager();

    var customClear = {
    canUndo: false,
    execute: function(wbContext, options, isUndo) {
    let sheet = wbContext.getSheetFromName(options.sheetName),
    sel = sheet.getSelections();
    for (let i = 0; i < sel.length; i++) {
    let curSel = sel[i];
    for (let c = curSel.col; c < curSel.col + curSel.colCount; c++) {
    if (!sheet.getColumnVisible(c)) {
    console.log("won't clear, hidden cell is selected");
    return true;
    }
    }
    }
    return cm.execute({
    cmd: "clear",
    sheetName: options.sheetName
    });
    }
    };

    cm.register(
    "customClear",
    customClear,
    GC.Spread.Commands.Key.del,
    null,
    null,
    null,
    null
    );
Need extra support?

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

Learn More

Forum Channels