How do I tell Datatables to not change column names as defined in the source data?

How do I tell Datatables to not change column names as defined in the source data?

wallsrwallsr Posts: 2Questions: 1Answers: 0
edited June 2022 in Free community support

Just loaded Datatables 1.10.21 and now the column names are being changed to camel case instead of matching the incoming data.
This requires debugging to view the column names and then editing the columhDef data and name values to match.
Shouldn't the column names in the row match the incoming column names?

Screenshot from Visual Studio of the Json object being sent to client
https://datatables.net/forums/uploads/editor/xh/ywllfh3gxjm7.png
Screenshsot of Chrome F12 row data:
https://datatables.net/forums/uploads/editor/ro/r4hgvmi54e9c.png

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • wallsrwallsr Posts: 2Questions: 1Answers: 0

    Colin, thanks for that info and it is a very good policy. Esp, since as I was trying to set up a publicly visible test case, I discovered that the problem was not Datatables at all! (of course, right?!) It turned out to be the Json serializer in .NET doing default camelCasing on Json property values--on purpose--what the heck? Anyway, when I changed the Json config to tell it to leave my property names alone, things began working as I expected. BTW: I ran into this issue after a pretty long slog converting a MVC 5 app to .NET 5 where I thought I was done except for some client stuff...(like handling my Json data!) I wasn't aware that the .NET Json lib by default converts property names to meet the "official" Json naming convention. Anyway, sorry for the trouble!

  • allanallan Posts: 61,656Questions: 1Answers: 10,094 Site admin

    That is a somewhat bizarre default setting isn't it! I wasn't aware of that either - I guess they've got a reason for it, but still...

    Good to hear you've found a solution and it is working now!

    Regards,
    Allan

Sign In or Register to comment.