type casting
type casting
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;}
]
}
This discussion has been closed.
Replies
@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.
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 ainput
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 - inpreSubmit
. That gives you the opertunity to modify the data before it is set to the server, or in this case to the table. You couldparseFloat()
it in there and then it will be a proper number for DataTables.Allan