0

I am working on ag-grid where I am validating a row. So the column name is Index and here is the validation function I am using.

 function numberValidate(params) {
        var new_number = parseFloat(params.newValue);
        if (isNaN(new_number)) {
            window.alert("Invalid value " + params.newValue + ", must be a number");
        } else {
            params.data.index= new_number;
            params.api.onNewRows();

        }
    }

If I edit a row and type any value, the variable new_number will get that value. It will check if it is numerical; if it is not, it will give a window.alert.

If its a number, it will update that row with that value.

My problem is this--> If I mention '56sfdfd', it takes 56 and updates in the row. However, it should display window.alert stating that '56sfdfd' is not a number.

Any idea how to correct this in my Javascript function above. Any inputs appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ayesha
  • 835
  • 4
  • 14
  • 33

1 Answers1

1

Try this way:

var new_number = Number(params.newValue);

Find more about this topic here.

Community
  • 1
  • 1
karaxuna
  • 26,752
  • 13
  • 82
  • 117