Flexgrid Angular - Allow AutoFill in FlexGrid but only for 1 column

Posted by: andrewalisa on 20 July 2021, 12:14 pm EST

    • Post Options:
    • Link

    Posted 20 July 2021, 12:14 pm EST - Updated 3 October 2022, 1:12 pm EST

    Hello!

    In a previous forum post, you helped me with the following: https://www.grapecity.com/forums/wijmo/flexgrid-angular---drag-a-

    To summarize, I wanted to use the Drag / AutoFill functionality in FlexGrid and you helped me out with that.

    The drag and drop (or AutoFill as you call it) works perfectly fine in FlexGrid with that code you posted on that forum post.

    Now, I need help to slightly modify the drag and drop. The data cannot go to a different column, so I can only drag and drop across rows, but not across columns.

    * “Here is what I want:”



    Notice the data staying only in 1 column



    * “Here is what I do not want:”



    Notice how the data is going across columns. I don’t want this:

  • Posted 22 July 2021, 4:59 am EST

    Hi Andrew,

    You may set the condition for restricting pasting among columns in the mouseup event on grid hostElement. Please refer to the code snippet:

     grid.hostElement.addEventListener("mouseup", (e) => {
                let selectedRange = grid.selection;
                if (pastingData != null) {
                    for (let i = selectedRange.topRow; i <= selectedRange.bottomRow; i++) {
                        if (Math.abs(selectedRange.leftCol - selectedRange.rightCol) == 0) {
                            grid.setCellData(i, selectedRange.leftCol, pastingData);
                        } else {
                            alert("Please drag cursor within the column to autoFill")
                            grid.selection = this.restoreSelection
                            return
                        }
                    }
                }
                pastingData = null;
            })
    
    

    You may also refer to the sample demonstrating the same:

    https://stackblitz.com/edit/angular-evhdmw

    Regards,

    Ashwin

Need extra support?

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

Learn More

Forum Channels