Editor: Accessing MJoin Columns
Editor: Accessing MJoin Columns
kmbonin
Posts: 59Questions: 16Answers: 0
I am using an MJoin to grab the last "time" record for an employee that has logged in to they system. The login/logout work fine, but I need to check to see if the employee is logged in/out, which is not working.
JSON snippet (MJoin returned):
"logan_dvpr_timeLog":[{"logan_dvpr_timeLog":{"taskID":"1462","userID":"38","loggedINYN":"Y","timeOUT":null,"timeIN":"11/5/2016"}}]}
JS snippet:
var table = $('#ProductionData').DataTable( {
ajax: './api/DVPRTaskData/DVPRTaskData/' + dvprID,
order: [1, 'asc'],
fixedHeader: true,
columns: [
{
"data": "logan_dvprTasks.taskID", "visible": false, "targets": 1
},
{
"data": "logan_dvpr_timeLog[0].loggedINYN", "visible": true
}
] ...
I am trying to access the first value of loggedINYN from MJoined table logan_dvpr_timeLog. Any ideas?
This discussion has been closed.
Answers
Use:
instead of the
[]
array notation. Its not quite correct Javascript, but it does make sense when the string gets broken up into its component parts and I can just doobject[property]
(i.e. it becomesdata['logan_dvpr_timeLog'][0]['loggedINYN']
).Allan
Thanks for the reply. I get this error when I use the dot notation: Requested unknown parameter 'logan_dvpr_timeLog.0.loggedINYN' for row 0, column 1.
Could you show me the full JSON returned by the server please?
Thanks,
Allan
Here are the first few records (the whole thing is quite extensive). You should be able to see the pattern here.
This is the key part:
To access
loggedINYN
from that you would need to use:There are two things worth noting here - 1. You'd get an error if the array was empty. There would be missing data if there was more than one entry in the array.
You could use:
to address that. i.e. get all entries from the array and comma separate them in the display.
Allan