Dataquery with Conditions in Table

Hi,
I am trying to make a query from the database and populate into the table. I went through the references and working fine. But it works only when I give the below code

My code:
// set the table columns
$w(“#myTable”).columns = [

{ 

“id”: “col1”,
“dataPath”: “at_in”, // matches field key from collection
“label”: “Time In”,
“width”: 100,
“visible”: true ,
“type”: “string”,
},
// the column that shows the document description
{
“id”: “col2”,
“dataPath”: “at_date”, // matches field key from collection
“label”: “Date”,
“width”: 100,
“visible”: true ,
“type”: “date”,
},
// the column for downloading the document
{
“id”: “col3”,
“dataPath”: “email”, // does not match field key from collection
“label”: “Email”,
“width”: 100,
“visible”: true ,
“type”: “richText”,
“linkPath”: “string” // matches field key from collection
}
];
wixData.query(“LM_Attendance”)
.find()
.then(result => {
let tableRows = result.items;
tableRows.forEach( (row) => {
let at_in = row.at_in;
let at_hours_table = at_in.getHours();
let at_min_table = at_in.getMinutes();
row.at_in = at_hours_table + " " + at_min_table;
row.download = ‘Download the doc’;
} );
// set the table row data
$w(“#myTable”).rows = tableRows;
} );
});

This is coming perfectly.

My question here : Its a attendance database, it might have multiple entries of “attendance In” and “attendance Out”. I need to take the first in and last out to consider that as “Time In” & “Time Out”

For Time in, I have used
wixData.query(‘LM_Attendance’).eq(‘at_date’, date).eq(‘at_email’, $w(“#email”).value).ascending(“at_in”)
.find()
.then(result => {
let item = result.items[0];

For Timeout, I use

wixData.query(‘LM_Attendance’).eq(‘at_date’, date).eq(‘at_email’, $w(“#email”).value).descending(“at_out”)
.find()
.then(result => {
let item = result.items[0];

This is how I take and work on the same. It works perfect.
When I use the same query for table query above

wixData.query(‘LM_Attendance’).eq(‘at_date’, date).eq(‘at_email’, $w(“#email”).value).ascending(“at_in”)

  •    .find()* 
    
  •    .then(result => {* 
    

let tableRows = result.items;
tableRows.forEach( (row) => {
let at_in = row.at_in;
let at_hours_table = at_in.getHours();
let at_min_table = at_in.getMinutes();
row.at_in = at_hours_table + " " + at_min_table;
row.download = ‘Download the doc’;
} );
// set the table row data
$w(“#myTable”).rows = tableRows;
} );
});

This is not working. The table is BLANK and console it says " forEach is not a function"

Please help me out.

This my link. https://www.ccplcnet.com/viewattendancedata

I looked at the your site and that page does not have the code that you posted above. I run Preview , and I get the following error:


The reason for the error is that you are setting the table data to a date field.

Thanks YIsrael appreciate your swift response. Am currently working on the same. thats why it was not there.

That why its not theres. Can you please advise where I am going wrong? I am attaching my question again.

I need the first row and repeat it in the table? the query is as below

My question here : Its a attendance database, it might have multiple entries of “attendance In” and “attendance Out”. I need to take the first in and last out to consider that as “Time In” & “Time Out”
For Time in, I have used
wixData.query(‘LM_Attendance’).eq(‘at_date’, date).eq(‘at_email’, $w(" #email “).value).ascending(“at_in”)
.find()
.then(result => {
let item = result.items[0];
For Timeout, I use
wixData.query(‘LM_Attendance’).eq(‘at_date’, date).eq(‘at_email’, $w(” #email ").value).descending(“at_out”)
.find()
.then(result => {
let item = result.items[0];
This is how I take and work on the same. It works perfect.
When I use the same query for table query above
wixData.query(‘LM_Attendance’).eq(‘at_date’, date).eq(‘at_email’, $w(" #email ").value).ascending(“at_in”) .find() .then(result => { let tableRows = result.items;
tableRows.forEach( (row) => { let at_in = row.at_in; let at_hours_table = at_in.getHours(); let at_min_table = at_in.getMinutes(); row.at_in = at_hours_table + " " + at_min_table; row.download = ‘Download the doc’; } ); // set the table row data $w(" #myTable ").rows = tableRows; } ); });

Sorry, but I have no idea what query you are trying to use and what happens. I really can’t debug code from a blog post. Please add the query that you want to the page and I will look at it.