Created New Data Structure Now Can't Populate Table

Created New Data Structure Now Can't Populate Table

zgoforthzgoforth Posts: 493Questions: 98Answers: 2
edited June 2021 in DataTables 1.10

Link to test case: https://jsfiddle.net/BeerusDev/drufevb8/2/ here is the logic I used to transform the data structure.

Here is how the data is shown when I console log it:

{
    "Department": "IT",
    "Employee": "Shap Dev",
    "Days": [
        {
            "Day": "Monday",
            "Date": "6/28/2021",
            "Status": "P",
            "Location": "Office"
        },
        {
            "Day": "Tuesday",
            "Date": "6/29/2021",
            "Status": "P",
            "Location": "Office"
        },
        {
            "Day": "Wednesday",
            "Date": "6/30/2021",
            "Status": "P",
            "Location": "Office"
        },
        {
            "Day": "Thursday",
            "Date": "7/1/2021",
            "Status": "P",
            "Location": "Office"
        },
        {
            "Day": "Friday",
            "Date": "7/2/2021",
            "Status": "P",
            "Location": "Office"
        }
    ]
};

I am trying to populate the Monday and Monday Status (followed by every other corresponding day and status), but I keep getting an alert that I am trying to access an unknown parameter?

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Your test case doesn't run.

    You have "data": "Days.Day[0]". Your array is Days so you need to do something more like this "data": "Days.0.Day".

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    The other issue that I am having with it as well is trying to apply the data to a tooltip over the cell with the columnDefs option:

    The table populates fine until I try to add to this :

    { "targets": 3,
                    "render": function (transformedResults, type, full, meta) {
                return type === 'display'? '<div title="Location: ' + Days.0.Location + '\n' + "Monday: " + Days.0.Date + '">' + data : data;  
                }     
                },
    
  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    If you want help with this please provide a running test case showing the issue. You can add the above example data like this:
    http://live.datatables.net/sasitavu/1/edit

    You can update this example to show the issue.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    Here is the updated example: http://live.datatables.net/sasitavu/2/edit

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    The Location in the tooltip is undefined becuase you don't have full.MondayLocation in your data structure. Same with moment(full.Monday). You need to reference them from the array, like this example for Monday:
    http://live.datatables.net/dafanuze/1/edit

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    Thank you! I was close but not close enough! One last thing that is really preventing me from getting back to where I was on my original example in my other post, is with this new data structure, I cannot figure out the issue with my object look ups in my rows.every() function: It tells me that jQuery.Deferred exception: Cannot convert undefined or null to object", "TypeError: Cannot convert undefined or null to object

    Here is my most recent test case: https://jsfiddle.net/BeerusDev/exzqys93/7/

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    I don't see the error message in your test case. Try searching Stack Overflow for the error to find suggestions of what the problem might be.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2
    edited June 2021

    It is because I commented that line out, it messes up the table if I leave it uncommented, and I will try I unfortunately got downvote bombed and have to wait 5 1/2 months to be able to ask one more question (super aggravating)… now it is just returning undefined and n/a. I think I need to reference transformedResults instead of Data but thats where the issues come into play: https://jsfiddle.net/BeerusDev/exzqys93/11/

    Lines 265-275

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Its hard to keep track of what you are trying to do with your solution. I guess this is the statement that is not working the way you want:

    var result = Object.keys(data).find(key => typeof data[key] === 'string' && data[key].startsWith(today));

    Start by debugging data to see what the structure is. Then adjust Object.keys(data) to access the portion of data you are interested in. And change typeof data[key] to match.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    https://jsfiddle.net/BeerusDev/exzqys93/45/

    I have tried a new method of going about this as recommended by someone else using a class function instead of a counter function, and when I insert it, it screws up all of the brackets even though they are matching?

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Look at the browser's console. You are getting this error:

    Uncaught SyntaxError: missing ) after argument list

    This forum is for helping with Datatables issues. Please limit your questions to Datatables issues. General Javascript coding and debugging is not appropriate for this forum.

    Kevin

Sign In or Register to comment.