SqlServer/.NET DateTime in input field

SqlServer/.NET DateTime in input field

wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

Description of problem:

I have various issues that just aren't affecting my implementation or I'm doing it wrong. These all are probably related in some way.

Editor js

            {
                label: 'StartDate',
                name: 'StartDate',
                type: 'datetime',
                def: () => new Date(),
                displayFormat: 'MM-DD-yyyy'
            },
            {
                label: 'EndDate',
                name: 'EndDate',
                type: 'datetime',
                def: () => new Date(),
                displayFormat: 'MM-DD-yyyy',
                
            }

Datatable js

            {
                data: "StartDate",
                title: "StartDate",
                render: function(data, type, row) {
                    return moment(data).format("MM-DD-yyyy");
                }
            },
            {
                data: "EndDate",
                title: "EndDate",
                render: function(data, type, row) {
                    return moment(data).format("MM-DD-yyyy");
                }
            }
  • Editor in .net seems to have zero affect using the GetFormatter. I've tried many different variations based on examples, but its untouched. I know I have two different ISO's in screenshot, I've been trying to get at least something to show changed in the INPUT field. https://editor.datatables.net/manual/net/formatters#Date-and-time

  • DatePicker isn't defaulting its date on selection.

  • Datatables is string sorting, not date sorting :neutral:

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Can you show me an example of the JSON data that is being loaded for the rows? Your GetFormatter looks like it should result in the data being in YYYY-MM-DD format, which is ideal.

    Datatables is string sorting, not date sorting

    Use the datetime renderer - at the moment you are returning a string for all types - hence why it is string sorting. The renderer will handle the formatting for you:

    render: DataTable.render.datetime('MM-DD-YYYY')
    

    Example here.

    displayFormat

    Could you try:

                displayFormat: 'MM-DD-YYYY',
                wireFormat: 'YYYY-MM-DD',
    

    please?

    It will depend on what the server is returning, but hopefully that will help. If not, it would be really useful if you could link to a page showing the issue so I can help to debug it and see the relevant data.

    Allan

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    Server is returning this:

    {"draw":null,"data":[{"DT_RowId":"row_1","Id":1,"StartDate":"2018-06-01T00:00:00","EndDate":"2018-09-01T00:00:00" ....

    Which it shows in the input field.

    I apologize but right now the page only exists in local development. There is nothing special about the date being returned. Its a SQL Server Datetime, to a C# DateTime property.

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    I tried the wireFormat before, but might have not tried it with the current puzzle pieces in place.

    Let me double check on that property.

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    From your comments it looks like the .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601 )) isn't returning what its supposed to.

    {
                    data: "StartDate",
                    title: "StartDate",
                    render: function(data, type, row) {
                        return DataTable.render.datetime('YYYY-MM-DD');
                    }
                },
    

    Makes the Datatables js show blank.

    {
                    label: 'EndDate',
                    name: 'EndDate',
                    type: 'datetime',
                    def: () => new Date(),
                    displayFormat: 'MM-DD-yyyy',
                    wireFormat: 'YYYY-MM-DD'
                    
                }
    

    Makes the Editor input field show blank.

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    Just like to add that I have been looking at the DatesController and the DateTimeController in the examples in .NET package and I feel like I've done the same thing as those controllers.

    I'll continue to examine.. but as of right now I'm still at a loss.

Sign In or Register to comment.