change the decimal seperator for field editing (.net)

change the decimal seperator for field editing (.net)

ASWSASWS Posts: 43Questions: 4Answers: 0
edited February 2023 in Editor

In our datatable setup numbers are formatted and displayed ok as intended:

123.456,78

...using below formatters:

                        .Field(new Field("contract.contract_vat_amount")
                        .Validator(Validation.Numeric("de-DE", null))
                        .GetFormatter(Format.FromDecimalChar('.'))
                        .SetFormatter(Format.FromDecimalChar(','))

Problem:
upon edit, in the editor form and when editing inline fields, the same number (incoming this way from db) is then shown as:

123456.78

Any easy way here to use a render function within the edit form, to change the seperator from "." to "," like:

editor = new $.fn.dataTable.Editor({
   ajax: "/api/AdminXYZ",
   table: "#xyzt",
   fields: [
 { label: "net:", name: "contract_vat_amount", function (render **maybe here ** --???!

We only need to change the decimal seperator, thousands seperators not needed, if easy solution at hand, means no plugins to install etc...

Replies

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    fields.setFormatter is the option you want to format a value for Editor. You'll need a corresponding fields.getFormatter to change it back into the format the database is expecting as well.

    Allan

  • ASWSASWS Posts: 43Questions: 4Answers: 0
    edited February 2023
    ...
    },
    { label: "MyNumberWithCommaSeperator:", name: "contract_vat_amount", def: 0,
                            getFormatter: function (val, data) {
                                return val;
                            },
                            setFormatter: function (val, data) {
                                return String(val).replace('.', ',');
                            } 
    },
    {...
    

    Thanks Allan!!

    Simple solution, works fine, done...

    PS:
    "getFormatter": modify your input / data before sending it back to the server
    "setFormatter": modify incoming data before display in editor form or inline edit upon click

Sign In or Register to comment.