Flexgrid percentage format issue when cell is empty

Posted by: rohaanthakare on 15 January 2019, 8:58 pm EST

    • Post Options:
    • Link

    Posted 15 January 2019, 8:58 pm EST

    Currently we have flexgrid with some cells having ‘p2’ format, initially grid is empty, so when we add any value in cell with p2 format, value is getting multiplied by 100 and shown when edit mode exited.

    e.g I put 12 in empty cell converted to 1200.00%

    what we are expecting is it should show 12.00% only.

    I checked this behavior in excel, and its working as we are expecting.

  • Posted 16 January 2019, 3:27 pm EST

    Hi Rohan,

    We are sorry for the inconvenience. This issue can be fixed by handling the cellEditEnding event. Here, we check if the cell’s previous value was null or not.

    If it was null, by checking if the value is int, we will convert the value of active editor by dividing 100.

    Please refer to the following fiddle sample for the same:

    https://jsfiddle.net/h8zewvLb/

    ~Manish

  • Posted 16 January 2019, 5:38 pm EST

    Hi Manish,

    Thanks for quick solution, just one more question, do we have any out of box solution for this, as i have lot for Wijmo grids in out application so need to add event handling for each grid.

  • Posted 16 January 2019, 10:18 pm EST

    Hello Rohan,

    You may apply this change for all the FlexGrid by overriding the cellEditEnding event behavior with existing one.

    Please refer to the following updated fiddle and the code snippet:

    https://jsfiddle.net/f7x3ysmc/

    var _oldCellEditEndingFn=wijmo.grid.FlexGrid.prototype.onCellEditEnding;    
        wijmo.grid.FlexGrid.prototype.onCellEditEnding=function(e){
        	var s=this;
        	var col=s.columns[e.col];
          if(col.dataType==2 && col.format.indexOf("p")>-1 && s.getCellData(e.row,e.col)==null){
            var val=s.activeEditor.value;
            if(val.indexOf(".")==-1){
              s.activeEditor.value=parseInt(val)/100;
            }
          }
          return _oldCellEditEndingFn.call(this,e);
        }
    

    Hope it helps!

    ~Manish

Need extra support?

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

Learn More

Forum Channels