Premium support for our pure JavaScript UI components


Post by shashank.yadav »

Hi Team,

We have special case w.r.t. cell copy paste feature, based on certain condition we want to permit copy-paste or cell selection.

A. To all nodes:
Restrict "Column Selection " or "Cell Copy paste" for column "Name".
B. To only parent nodes:
Restrict "Column Selection " or "Cell Copy paste" for column "Start Date", "Duration", "Finish Date" only.

Thanks,
Shashank Yadav
Hatch Digital


Post by ghulam.ghous »

Hi Shashank,

What do you mean by Column Selection? I assume, you want to prevent selection of cells based on certain conditions. Though to prevent copy paste and cell selection for certain cells does not have built in support but you can always achieve it with few tweaks in events offered by these two features. Here's what you can do:

    listeners : {
        beforeCopy(data) {
            if (
                data.cells[0].column.text === 'Name' || data.cells[0].record.isParent) {
                return false;
            }
            return true;
        },
        beforeSelectionChange(data) {
            if (data.selectedCells[0].column.text === 'Name' || data.selectedCells[0].record.isParent) {
                return false;
            }
            return true;
        }
    },

This is a code for one single cell selection and copy but you can change it to handle multiple cells as well.
https://bryntum.com/products/gantt/docs/api/Grid/view/mixin/GridSelection#event-beforeSelectionChange
https://bryntum.com/products/gantt/docs/api/Grid/feature/CellCopyPaste#event-beforeCopy

Hope it helps!

Regards,
Ghous


Post by shashank.yadav »

Thanks Ghous.

That is correct we want to restrict the selection so that user won't be able to copy & paste the cell "name".

We tried above solution, even function is executing code properly and returning false, but we can still see the "name" is getting copied and pasted to another cell.

Any other lead, please.

Thanks,
Shashank Yadav
Hatch Digital


Post by ghulam.ghous »

Hi Shashank,

I have tried in our advanced demo with the above shared code and I was not able to copy any cell from the Name Column and in the other columns, I was not able to copy any parent row cell. See the clip here: https://drive.google.com/drive/folders/1azwCSjpCF01orehnbTnISkq7DMKIa8tK?usp=sharing

The only issue I noticed is the ability to paste the previously copied values in the name column. For that you need to implement the logic similar to one in the beforeCopy in beforePaste event. https://bryntum.com/products/scheduler/docs/api/Grid/feature/CellCopyPaste#event-beforePaste

If you are still facing the issue, can you please elaborate a bit with clip maybe.

Regards,
Ghous


Post by shashank.yadav »

Hi Ghous,

Thanks for your response. I saw your attached video and it seems to be working for you. Somehow it's not working for me. I am attaching a sample app to reflect my issue. If you could have a look at it and maybe suggest something that i am missing.

Thanks,
Shashank yadav
Hatch Digital

Attachments
advanced_export.zip
(319.62 KiB) Downloaded 14 times

Post by ghulam.ghous »

Hi Shashank,

Moving events to config worked for me. Is there a reason you are using them inside ngAfterViewInit? See the attached zip file:

// in config file
listeners:{
        beforeCopy(props){if(props.cells[0].column.field.toLowerCase() == "name" ){
                return false;
            } 
            else {
                return true;
            }
        },

    beforePaste(props){ 
        if(props.cells[0].column.field.toLowerCase() == "name")
        {
            return false;
        } 
            return true;
    } 
}

// in markup file
[listeners]                = "ganttConfig.listeners"
advanced_export 2.zip
(465.5 KiB) Downloaded 14 times

Regards,
Ghous


Post by shashank.yadav »

Thank you Ghous. It worked.


Post Reply