type casting

type casting

Bindrid2Bindrid2 Posts: 79Questions: 4Answers: 12

Using editor on numeric fields is recasting the data from numbers to strings short of creating a numeric field plug-in or using the edit event handler to convert it back to numbers.
In the render below, the numbers are properly summed when the table is first displayed.
After editing, it ends up being a string so numbers get concatenated.

   this.editorDef = {
        table: "#tblFYDP",
        fields: [
            {
                name: "FiscalYear", label: "Fiscal Year", type: "readonly", attr: {tabIndex:-1}
            },
            { name: "Direct", label: "Direct"} ,           
            { name: "Reimbursable", label: "Reimbursable" }

        ],
        formOptions: {
            inline: {
                onBlur: 'submit'
            },
            bubble: {
                buttons: false,
                onBlur: "submit"
            }
            
        }
    };

   this.tableDef = {
       columns : [
            {data:"Direct"},
            {data: "Reimbursable"},

// yes, I could use parseFloat but I have other dependencies so I would end up putting parse float all over the place.
            {data:null, render:function(rowData) { return rowData.Direct + rowData.Reimbursable;}
       ]
  }

Replies

  • Bindrid2Bindrid2 Posts: 79Questions: 4Answers: 12

    @allan it took two years to get my stupid company to get the Editor licenses so I am now playing catch up with knowledge about it.

  • allanallan Posts: 63,506Questions: 1Answers: 10,471 Site admin

    Unfortunately, what is happening here is that Editor puts the values into input elements and then reads them back. When you read the value from a input it is always a string.

    So you will need to use a parseFloat(), but I think we can do it in such a way as to put it in only one place - in preSubmit. That gives you the opertunity to modify the data before it is set to the server, or in this case to the table. You could parseFloat() it in there and then it will be a proper number for DataTables.

    Allan

This discussion has been closed.