Date field showing time component when datepicker is present

Date field showing time component when datepicker is present

lcoglcog Posts: 24Questions: 5Answers: 0

I have a SQL Server table with a field defined as "date".

I set up a "Get" formatter in "C#" like this: .GetFormatter ( DataTables.Format.DateTime ( "MM/dd/yyyy" , "MM/dd/yyyy" ) );

When the date picker pops up it shows the time component:

2018-03-08T00:00:00

The date picker works great, but I would like to get rid of the time component displaying. Is there a way to do this?

Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin

    Hi,

    Could you run the debugger on the table and let me know the debug code please?

    Thanks,
    Allan

  • lcoglcog Posts: 24Questions: 5Answers: 0

    I think I did the debugger correctly. It returns https://debug.datatables.net/uneqag Is that correct?

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin

    Perfect - thanks. Although that reminds me that I need to update its styling for the new DataTables site design...

    Looking at the debug data it appears that the time part is loaded into the DataTable:

    "DateStart": "2018-03-06T00:00:00",

    Unlike DataTables, Editor doesn't have a rendering option to convert values before displaying them. Are you able to modify the date value before inserting it into the DataTable. I think that you are adding it via the API? So pre-processing the data would be the way to do it.

    Allan

  • lcoglcog Posts: 24Questions: 5Answers: 0

    Will I want to pre-process the data on the server side or the client side? What does the "GetFormatter()" do? I thought that would set up the format to return the data in?

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin

    Yes - if you are using the .NET libraries, then GetFormatter is the way to do this. It will format the data based before it is sent to the server-side (i.e. as part of the get).

    I'm not clear on how you are populating the table and using the server-side libraries though. The debug trace doesn't show any Ajax configuration for the table.

    Allan

  • lcoglcog Posts: 24Questions: 5Answers: 0

    The first populating of the table comes from getting data from a stored procedure and then using the ".rows.add()" to put the data into the table.

  • lcoglcog Posts: 24Questions: 5Answers: 0

    The data returned by the stored procedure is ran through a JSON serializer that converts the C# datetime to a MM/dd/yyyy, so that appears properly the first time in the datepicker popup.

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin

    Okay - so to clarify - it is inserted without the time part on first load/ But then something else loads in data that does have the time part? What is it that does that?

    Allan

  • lcoglcog Posts: 24Questions: 5Answers: 0

    Correct on the first load. Then if I update the field thru the Editor date picker popup or thru the edit of the whole row, the field will now include the time portion. At this point I am using the DataTables Editor.

    First time in:

    Change the date thru the date picker:

    Then after clicking on Update in the date picker the row looks like this:

    The C# code is:

    And the getformatter for the date field is:

  • lcoglcog Posts: 24Questions: 5Answers: 0

    I'm pretty sure it is something on the C# side, because I got into the debugger thru the client "submitSuccess" and the data has the time portion in it:

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin

    Can you show me a bit more of your C# code please, particularly the lo_LDTFs and how you are using lo_DTF there?

    Thanks,
    Allan

  • lcoglcog Posts: 24Questions: 5Answers: 0

    They are declared as:

    And the singular DataField is allocated as:

    Then the singular DataField is added to the collection like this:

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin
    Answer ✓

    It looks like the get formatter might be getting bypassed on edit. Without being able to see the whole code though, it is impossible to say I'm afraid.

    Is the type for this field a string? Keep in mind that DateTime can't be directly represented in JSON, but I'm not clear that that is the issue. It sounds like the get from the database is taking a different path on edit than from when loading the table. That shouldn't be the case if you are using the .NET libraries for Editor.

    Allan

This discussion has been closed.