Flexgrid - Prevent selection from hyperlinks

Posted by: ECHRLicences on 26 October 2018, 8:17 am EST

    • Post Options:
    • Link

    Posted 26 October 2018, 8:17 am EST

    Hi,

    When a user click on a hyperlink or a button in a cell from a flexgrid, the selection will be automatically updated.

    It should not be the default behaviour, or at least there should be a way to prevent it.

    I’m attaching a few demos with the unexpected behaviour.

    Es6 version:

    https://stackblitz.com/edit/js-k4dwyt

    Angular 6 version:

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

    Stopping the event bubbling does not seems to do anything.

    As a workaround I could disable the selection for specific rows using the “onSelectionChanging” event of the grid.

    Unfortunately this solution does not work properly with mixed contents (e.g. a cell containing both some text and a hyperlink)

    Is there any way to solve this issue ?

  • Posted 29 October 2018, 1:20 am EST

    To prevent the default selection behaviour of the grid, you need to attach handler for the ‘mousedown’ event in capturing phase and call preventDefault() as required.

    Please refer to the following code snippet:

    flex.hostElement.addEventListener('mousedown', (e)=>{
          if(e.target.tagName == 'A') {
            e.preventDefault();
          }
        }, true);
    

    You may find the updated samples here:

    ES6: https://stackblitz.com/edit/js-dgmkwj?file=index.html

    Angular: https://stackblitz.com/edit/angular-wexfxw?file=src%2Fapp%2Fgrid.component.ts

    ~Sharad

  • Posted 29 October 2018, 3:51 am EST

    Hi Sharad,

    It worked !

    Thank you very much.

    Have a nice day.

Need extra support?

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

Learn More

Forum Channels