postgresSQL can not input decimal type

postgresSQL can not input decimal type

mac129mac129 Posts: 6Questions: 2Answers: 0

Hi!
I bought and downloaded the .Net Core demo with link https://editor.datatables.net/download/index and tried the postgres demo.
I noticed that if I edit the column "Extn" with a decimal input showed in pic,
.

it will automatically be round to integer, which means it can not input a decimal. I check the database and the type is varchar, it should be right to input a decimal, but it didn't work. And I change the database "extn" field type from varchar to numeric(9,2), it still can not input decimal...

Can you help me? Thanks

This question has accepted answers - jump to:

Answers

  • mac129mac129 Posts: 6Questions: 2Answers: 0

    It worked in mysql, but my project database is postgresSQL :'(

  • mac129mac129 Posts: 6Questions: 2Answers: 0
    edited November 2022

    In this example, the Model is:

    namespace EditorNetCoreDemo.Models
    {
        public class StaffModel
        {
            public string first_name { get; set; }
    
            public string last_name { get; set; }
    
            public string position { get; set; }
    
            public string email { get; set; }
    
            public string office { get; set; }
    
            public string extn { get; set; }
    
            public decimal age { get; set; }
    
            public decimal salary { get; set; }
    
            public string start_date { get; set; }
        }
    }
    

    the controller is:

    public ActionResult Staff()
            {
                var dbType = Environment.GetEnvironmentVariable("DBTYPE");
                var dbConnection = Environment.GetEnvironmentVariable("DBCONNECTION"); 
    
                using (var db = new Database(dbType, dbConnection))
                {
                    var response = new Editor(db, "datatables_demo")
                        .Model<StaffModel>()
                        .Field(new Field("first_name")
                            .Validator(Validation.NotEmpty())
                        )
                        .Field(new Field("last_name"))
                        .Field(new Field("extn")
                            .Validator(Validation.Numeric())
                        )
                        .Field(new Field("age")
                            .Validator(Validation.Numeric())
                            .SetFormatter(Format.IfEmpty(null))
                        )
                        .Field(new Field("salary")
                            .Validator(Validation.Numeric())
                            .SetFormatter(Format.IfEmpty(null))
                        )
                        .Field(new Field("start_date")
                            .Validator(Validation.DateFormat(
                                Format.DATE_ISO_8601,
                                new ValidationOpts { Message = "Please enter a date in the format yyyy-mm-dd" }
                            ))
                            .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
                            .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                        )
                        .TryCatch(false)
                        .Process(Request)
                        .Data();
    
                    return Json(response);
                }
            }
        }
    

    the is in View is

    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
            ajax: "/api/staff",
            table: "#example",
            fields: [ {
                    label: "First name:",
                    name: "first_name"
                }, {
                    label: "Last name:",
                    name: "last_name"
                }, {
                    label: "Position:",
                    name: "position"
                }, {
                    label: "Office:",
                    name: "office"
                }, {
                    label: "Extension:",
                    name: "extn"
                }, {
                    label: "Start date:",
                    name: "start_date",
                    type: "datetime"
                }, {
                    label: "Salary:",
                    name: "salary"
                }
            ]
        } );
    

    I have tried changing prop in model:public decimal extn { get; set; } and fn.dataTable.render.number in JS of View, set numeric(9,2) type in PgSql, and added

    .Field(new Field("extn")
                  .DbType(System.Data.DbType.Decimal)
    )
    

    Or

    .Field(new Field("extn")
                  .DbType(System.Data.DbType.AnsiString)
    )
    

    but all those methods did not work...

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • mac129mac129 Posts: 6Questions: 2Answers: 0

    But even if I don't change any code, I won't meet any problems in mysql Database. Is there some additional settings in pgsql I need to change or set?

  • allanallan Posts: 57,703Questions: 1Answers: 9,195 Site admin
    Answer ✓

    Hi,

    I'm just looking into this. I can reproduce the issue exactly as you say in our .NET Postgres dev environment.

    Allan

  • allanallan Posts: 57,703Questions: 1Answers: 9,195 Site admin
    Answer ✓

    I've committed a fix for this now.

    I've build the dlls and you can download them here - just install the correct dll for the version of .NET you are using (use the .netcoreapp2.1 version if you are using anything other than .NET Framework 4.x).

    Regards,
    Allan

  • mac129mac129 Posts: 6Questions: 2Answers: 0

    Thank you very much! That solved my problem! :D :D :D

Sign In or Register to comment.