[ Flexgrid ] make column unselectable

Posted by: vorobjovkirill on 20 September 2017, 2:34 am EST

  • Posted 20 September 2017, 2:34 am EST

    Good day Wijmo team,

    Just a quick question. Is it possible to make a flexgrid column unselectable ?

  • Posted 22 September 2017, 8:58 am EST

    Hi,

    For this, you need to handle slectionChanging event and need to cancel for the column you want to cancel selection.

    
    flex.selectionChanging.addHandler(function(s,e){
    	if(e.col==1){
    		e.cancel=true;
    	}
    });
    
    

    Thanks,

    Manish Kumar Gupta

  • Posted 23 January 2019, 5:50 pm EST - Updated 3 October 2022, 8:12 pm EST

    Hi,

    Is it possible to cancel selection of specific cells when selecting over a range of cells?

    For example (see attachment):

    • when selecting a single cell (the one with 138.07) it gets cancelled as expected
    • when selecting over a range, the cell gets selected

    Best,

    Martin

  • Posted 25 January 2019, 5:32 am EST

    Hi,

    FlexGrid only allows the continuous range to be selected so we cannot do something like select a range of cells and unselect some of them.

    What we can do if stop the grid from selecting a range if any of the cells in the range is unselectable. To do so we need to handle the selectionChanging event and cancel the event if any of the cells in the range is unselectable.

    Please refer to the following code snippet:

    var unselectableCells = [
      '1:2', '0:1', '2:3', '3:2', '4:1', '5:0'
    ];
    function isRangeUnselectable(rng){
      for(var i = 0; i < unselectableCells.length; i++){
        var temp = unselectableCells[i].split(':');
        var r = Number(temp[0]), c = Number(temp[1]);
        if(rng.contains(r, c)){
          return true;
        }
      }
      return false;
    }
    grid.selectionChanging.addHandler((s,e)=>{
      e.cancel = isRangeUnselectable(e.range);
    });
    

    You may also refer to the following sample which demonstrates the same: https://stackblitz.com/edit/js-zpl4za?file=index.js

    ~Sharad

Need extra support?

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

Learn More

Forum Channels