Entering 0 into empty cell not possible

Posted by: moritz.neugebauer on 1 February 2021, 7:41 am EST

  • Posted 1 February 2021, 7:41 am EST

    Dear Wijmo Team,

    When trying to enter 0 into an empty cell that is from type Number or Float, the cell stays empty. After writing a different number (something between 1-9) into the cell, writing 0 into the cell is possible.

    It seems that the problem really is writing 0 into a new empty cell.

    My newItemCreator looks basically like this:

    
    this.data.newItemCreator = () => {
     let newItem = ...;
    
    newItem.content = this.attributes[j].datatyp === this.Datatype.BOOLEAN ? false : '',
    
    return newItem
    }
    
    

    Am I doing something wrong here?

    Best regards

    Moritz

  • Posted 2 February 2021, 2:41 am EST

    Hi Moritz,

    Can you let me know the column information of the number column (if you are generating it manually)? Also, does the newItemCreator initializes this particular column in any way?

    I am also adding a sample link at the bottom. If possible, can you modify it so that it replicates your issue?

    https://stackblitz.com/edit/angular-9-0-0-rc-1-61nusu

    Regards,

    Ashwin

  • Posted 9 February 2021, 5:47 am EST

    Hi Ashwin,

    the column looks like this:

    
    {
    "header":"integer",
    "binding":"attributes.914799.content",
    "dataType":2,
    "align":"right",
    "format":"g",
    "isRequired":false
    }
    
    ```.
    
    The columns are generated in the initialize() method of the grid based on attributes that are loaded from the backend. The columns are stored in the columnLayout from wjcGrid.FlexGrid.
    
    The newItemCreator does not initialize the particular column. The error also appears in existing rows when I add an integer column by adding a new attribute in the backend. (Columns in the grid are generated based on the attributes that are sent from the backend to the client).
    
    I will try to modify your example, but that may take a while.
    
    Best regards
    Moritz
  • Posted 9 February 2021, 6:12 am EST

    Hi Ashwin,

    maybe it’s the dataType that’s causing the issue?

    Your code:

    
    <wj-flex-grid #grid [showMarquee]="true" [allowAddNew]="true" [selectionMode]="'MultiRange'" [(itemsSource)]="data1">
    	<wj-flex-grid-column header="Sales" binding="sales" dataType="Number" [isRequired]="true"></wj-flex-grid-column>
    </wj-flex-grid>
    
    

    My code:

    
    <wj-flex-grid #grid [showMarquee]="true" [allowAddNew]="true" [selectionMode]="'MultiRange'" [(itemsSource)]="data1">
    	<wj-flex-grid-column header="Sales" binding="sales" dataType="2" [isRequired]="true"></wj-flex-grid-column>
    </wj-flex-grid>
    
    

    https://angular-9-0-0-rc-1-nj627o.stackblitz.io

    When changing the dataType from “Number” to “2”, I can’t type anything into the cell.

  • Posted 9 February 2021, 7:08 am EST

    Hi Ashwin,

    even the cellEditEnding Handler seems to be fine:

    
    flexdata.cellEditEnding.addHandler((s: wjcGrid.FlexGrid, e: wjcGrid.CellEditEndingEventArgs) => {
    let oldValue = s.getCellData(e.row, e.col, false);
    let newVal: any = s.activeEditor.value;
    let col = s.columns[e.col];
    
    console.log("oldVal: ", oldVal);
    console.log("newVal: ", newVal);
    
    if (col.dataType === wjcCore.DataType.Number) {//also valid for float
                    console.log("dataType number");
                    newVal = wjcCore.changeType(s.activeEditor.value, wjcCore.DataType.Number, col.format);
                    console.log("newValu after changetype: ", newVal);
    }
    }
    
    

    See a video of the behaviour

    entering0.mov.zip

    Best regards

    Moritz

  • Posted 9 February 2021, 8:34 am EST

    Dear Ashwin,

    I think I found the problem:

    This is my itemCreator

    
    newItem.content = this.attributes[j].datatyp === this.Datatype.BOOLEAN ? false : '',
    
    

    There seems to be an issue with numbers when default value is ‘’.

    I was able to replicate the issue:

    https://stackblitz.com/edit/angular-9-0-0-rc-1-nj627o?file=src/app/app.component.ts

    In line 25 it says:

    
    integer: ''
    
    

    This is causing the issue.

    When I switch it to

    
    integer: null
    
    

    it’s working.

    Thanks for your help :slight_smile:

    Best regards

    Moritz

  • Posted 9 February 2021, 8:41 am EST

    Hi Ashwin,

    sorry for bothering you again.

    Changing the default value for numbers in the itemCreator for ‘’ null made it work for cells in new rows. But empty number cells in existing rows still have this issue because they already have the “buggy” default value.

    Do you have an idea how to get rid of that behaviour for number cells that already have that “buggy” default value?

    Best regards

    Moritz

  • Posted 10 February 2021, 5:28 am EST

    Hi Moritz,

    Please do not apologize for asking questions.

    Refer to the sample link below:

    https://stackblitz.com/edit/angular-9-0-0-rc-1-4vidi9

    Before setting the itemsSource of the grid, first, convert it into a JSON string using JSON.stringify method and then parse it using JSON.parse method. The second parameter of the parse method is a reviver function which can be used to convert certain values like “” to null like in your example. In this sample, each integer is “” but its value is converted to null using reviver function.

    ~regards

Need extra support?

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

Learn More

Forum Channels