Leaving data alone
Leaving data alone
dhutton@creativeone.com
Posts: 59Questions: 15Answers: 0
I'm sure this is out there somewhere I'm just not using the right search criteria. If we input something like January 21-23 into a text field (using latest DT & Editor) it converts that to a date. Is there a universal way to tell DT / Editor to treat the data as verbatim and not convert to a date (or an int ... etc.)?
This discussion has been closed.
Answers
If you set
fields.type
to betext
, that should do the trick.See example here for setting those types.
Colin
Does that work for you? It doesn't for me in my set up. Text is the default and I tried explicitly defining the type as textarea too. Same behavior. It takes January 21-23, converts it to one day's date, deletes the original content and replaces it with the conversion. So I can't even tell what the originator put in to change it back.
I haven't ruled out doing something wrong my end but this looks like a bug - the code is changing data types on me. Is there maybe another way I can keep the conversion from happening?
Preconditions
Expected results
String is saved as-is
Actual results
String is converted and deleted, converted date is new value
Steps to reproduce
1. Type January 21-23 into a text field and submit (dialog or inline)
2. Observe
Work around
None
Is the conversion stored as a date in the DB?
Looking at the Developer Tools what is the XHR response when editing the field?
What does this actually look like?
Although this isn't saving to the server this example doesn't make any conversions:
http://live.datatables.net/wozozugu/1/edit
Kevin
I am posting through the server / controller so maybe the conversion is happening in there. I don't see any custom code that would be causing this, the set up is pretty simple compared to our other implementations (and all of our implementations are doing it). Anywhere I have a text field and type that in, it's converted into a date and written to the db that way.
You may need to help me with the XHR you're trying to get
The diagnosis section of this technote will walk you through the steps:
https://datatables.net/manual/tech-notes/1
You can see the request with the
January 21-23
field and the response from the server. That should help determine where to look next. Let us know what you find.Kevin
Also could you upload a trace for me using the debugger. Click the Upload button and then let me know what the debug code is.
What is the server-side code you are using?
Allan
ok thanks for the link on XHR
So I clear my console, go to network / xhr and then type in January 21-23 and hit enter to submit. I can see in the response that the date is already there, so I'm assuming that means it's happening in the js first before it gets to the controller.
Here's the controller code:
Allan I clicked upload, it left me a shortcode but when I go there I got a 404. I tried it again and hit upload and still 404. When I tried a variation the 3rd time it said only one request per minute. So maybe I didn't do something right.
The Request is what you want to look at to see what is sent by the client. In Chrome that would be in the Headers (scroll to the bottom). The Response is the data back from your server.
Kevin
oh ok. So when I clear my console, input January 21-23 and hit enter, this is what my headers say:
action=edit&data%5Brow_75%5D%5Banswer%5D=January+21-23&data%5Brow_75%5D%5Bdatemodified%5D=Thu+Jan+09+2020+10%3A18%3A26+GMT-0600+(Central+Standard+Time)
so I think that's telling me the problem isn't on the client side?
Although the data starts out already converted. So I'll be more sequential as to what I'm seeing:
1) Data says this in the field: 2023-01-21 00:00:00
2) I edit it and replace it with January 21-23
3) Then I see what I sent above in the header / form data
That shortcode is what we need for the debugger. Please could you try that again and post the shortcode here. You'll get the 404 as it's protected so only staff are able to access it.
Colin
Gotcha, I saved it just in case that's how it works:
https://debug.datatables.net/uzawiw
I'd agree with that. It is submitting
January 21-23
as a value, so any conversion is happening at the server-side.Can you show me also
C1FaqsModel
? Have you got theanswer
property as just a string? Also, what is the data format in the database - is it plain text?Allan
Here's the C1FaqsModel
This is just weird!
Immediately before
.Process(Request)
can you add.Debug(true)
. Then reload your page and use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.Thanks,
Allan
Hey Allan, sorry for the delay. Here's my debug:
https://debug.datatables.net/osawac
Thanks! I see:
In the response, so no question that something is converting it into ISO8601, but I'm not yet sure what!
A little more information I need to request I'm afraid. If you have the network inspector open, then submit the edit request that results in this error, can you show me the:
Thanks,
Allan
Here's the response and the headers info below that
General
Request URL: https://localhost:44369/api/C1Events/getAllFaqsByEvent/9876
Request Method: POST
Status Code: 200
Remote Address: [::1]:44369
Referrer Policy: no-referrer-when-downgrade
Response Headers
access-control-allow-origin: *
content-type: application/json; charset=utf-8
date: Wed, 29 Jan 2020 21:49:31 GMT
server: Microsoft-IIS/10.0
status: 200
x-powered-by: ASP.NET
Request Headers
:authority: localhost:44369
:method: POST
:path: /api/C1Events/getAllFaqsByEvent/9876
:scheme: https
accept: application/json, text/javascript, /; q=0.01
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
content-length: 151
content-type: application/x-www-form-urlencoded; charset=UTF-8
cookie: ***
origin: https://localhost:44369
referer: https://localhost:44369/C1Events/DetailsFaqs/9876
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
x-requested-with: XMLHttpRequest
Form Data
action: edit
data[row_75][answer]: January 21-23
data[row_75][datemodified]: Wed Jan 29 2020 15:49:31 GMT-0600 (Central Standard Time)
Excellent - thank you!
So in the SQL statement we have:
where
@answer
is bound as:So that's good! The value should be in the database. Can you use SQL Studio or similar to look at your data directly in the database and confirm that it is there? I suspect it will be.
What is not so good is the JSON response:
That suggests to me, that somewhere between reading the value from the db (assuming it was written correctly - that will be important to know), and writing it out to the client, it is being converted into a
DateTime
.Your model and controller are just as above? You don't have any event handlers or any formatters?
Is it SQL Server you are using? What version of it?
Thanks,
Allan
My database is PostGreSQL. The data looks exactly like what's pictured in the UI's table using PgAdmin (the UI to the db similar to SQL Studio).No event handlers or formatters.
The fact that it's doing this to me in all tables I use throughout my app, it's sounding like it has something to do with DT interaction with postgres since that's the common denominator in this. I've had problems with DT & postgres before since postgres does things like wraps mixed case table and column names / data in double quotes vs. single.
My data type in my db is text and I can manually add January 21-23 and save it via pgadmin and confirm the value sticks, so it's something to do with how DT is reading that data from postgres and converting it to a date for some reason (or I guess reading the submitted data and converting it and writing it that way). At least that's what it seems to be. If I'm correct any dt/editor set up to point at a postgres db will reproduce.
Do you mean your image above from 17th Jan? The screenshot there doesn't show the "January 21-23" data in the
answer
column (or an ISO date - I think that row has just been clipped) so I'm not clear if the db hasJanuary 21-23
in it or an ISO date?edit I'm trying to clarify if the problem is the data being written to the db, or being read from the db. The SQL debug above shows that Editor is writing the correct string to the SQL statement, so one possibility is that the database driver is converting the string to a date. Another is that it is doing it on read. Or something else is going wrong on read.
Thanks,
Allan
On the first question, I mean I see the same result looking at the data via pgAdmin that I do looking at the finished data in the datatable.
I know the db is capable of just holding January 21-23 as a string because I've done it via pgAdmin. So I don't think the problem is happening when reading the data from the db I think it's converting before writing it to db. Presumably if I just write January 21-23 as a value to one of my entity models using my own code that I would see that written as-is in my db. If I do it through dt it's being converted. I just can't tell what's doing it.
If it's the postgres driver than anyone running a postgres db should see the same results, at least anyone using postgres and datatables / editor together I guess.
Right - If you are seeing the ISO date when looking at the table with pgAdmin, then there is no question in my mind, that the issue is on writing to the db. Looking at the SQL debug above we can see that the SQL statement is being bound with
January 21-23
.I wonder if specifying it as a string type for the db would help (apologies I can't try this right now):
just after the
.Model()
call for that. Could you add that in then try it again, and if it still doesn't work show me the response from the server (the JSON) again?Thanks,
Allan
It didn't work but I got an interesting exception:
Apologies for the delay in getting back to you on this. I will do so later on today.
Allan