Search code examples
javascriptw2ui

W2UI Grid selects column with select type 'cell' and right click on any cell?


I think to have an issue with W2UI's grid. I have the "cell" selection type and I see that the whole column is selected if you click on a cell with the mouse right button.

Specifically it happens when you have no cell selected or you click on a cell in another column than the selected cell's one. To test the described behaviour, you can use any of the available demos on jsFiddle, setting selectType: 'cell' in grid options.

It's a strange behaviour in my opinion and I would like to know how to change it. Is it possible?


Solution

  • Option 1

    The easiest way to work around this, is to set the grid context menu to an empty function:

    grid.contextMenu = function() {};
    

    or in the constructor:

    $('#grid').w2grid({ 
        name: 'grid', 
        contextMenu: function() {}
    });
    

    This will however then show the browser's default context menu on right click.

    Option 2

    If you do not want the browser's context menu to show up, instead of an empty function, implement a function that executes event.preventDefault():

    grid.contextMenu = function(recid, column, event) { event.preventDefault(); return false; }
    

    Here's a fiddle based on the Spreadsheet Like Grid Demo

    Option 3

    If you need the w2ui default context handling, and only want to get rid of the column selection, I'm afraid you'll have to modify the source and remove the following line in the contextMenu function:

    if (!selected && column != null) obj.columnClick(this.columns[column].field, event);
    

    or copy the whole original code (sans the mentioned line) for your own implementation of your grid's contextMenu function.