The data I have stored on my database is stored in an array of key-value pairs, where the key is the column header and the value is the value for the row at current array index. I’m getting the key-value array as a json object and I’m trying to add it to the data field. Currently the data all populates but not in the correct columns.
How do I make sure that the Key-value matches the column header? I can’t hard code it because I have different column headers for different data sets. I don’t completely understand the constructor properties of the table and what datatypes do what when you create one.
Here’s a little JSON parse demo that I’ve prepared https://jsfiddle.net/zxrmet9j/ Please describe the strcture of your JSON file and which options are the one to build
I’m sending an AJAX request to the server for 2 things:
An array of strings that represent the Column Headers
Example:
colHeaders = [“Sample ID” , “Sample Type” , “Project Name” … ]
Currently it’s populating the column headers properly and reading all the values into the spreadsheet properly. The problem is that the values and the headers aren’t aligned, so project name will be under sampleID and so on. I have a feeling that I can make sure they’re in the correct order by making sure the colHeaders and Values are in the same order, but that seems like it could lead to potential bugs down the line. I’d like to explicitly assign the value to be in the column where the key matches the column header.
I’m also writing the server methods that returns this data, so I can modify things on that end and change up the data being pulled from the database if needed. And I need to also model whether or not a column is editable and if the column is populated with drop down menus. So the column header structure might turn into something like this:
Is it possible to put all of that in a JSON object and then just assign it to columns? Because I can create various config json objects server side and then return them to the javascript after the AJAX call to generate the spreadsheet.
It worked! I just made the column json object on the back end and added it to my config. When I made the AJAX call to get the data for the user I pulled the config for them and added it to the column value. Formatted the whole table correctly and the data is in the correct columns now.