I am not a programmer but with guidance can adapt code for my use. I have 4 questions.
I have a data collection for members to log hours and miles. I have figured out how to have them enter one row of data at a time and to display a read-only table of data entered by the member.
1. How can the member edit data in a specific row once it's been submitted?
[UPDATE: I have figured out how to use previous and next buttons to allow the user to edit one row at a time. Not elegant, but workable.]
2. How can I pre-fill the logon user name into one of my fields (so I can easily identify who entered it rather than matching to the owner ID)? The data collection is called MilesHoursLog and the field is loginEmail. This is code I found on the forum but I don't know how I'm supposed to define the data collection or data item to fix the error that they aren't defined (in bold). Help on what's missing or incorrect would be greatly appreciated!
UPDATE: figured out the error; here is the code that works:
import wixUsers from 'wix-users'; let user = wixUsers.currentUser; let userId = user.id; let isLoggedIn = user.loggedIn; let userRole = user.role; user.getEmail() .then( (email) => { let userEmail = email; // "user@something.com" $w('#input31').value = userEmail; } );
3. How can user select data for a specific data range so they can report totals by calendar year (mileage for tax purposes) or by school year (Sept - June)?
4. How can I display totals for the set of records displayed (total hours, total miles)?
This is a screen shot of the member page where they enter or edit data (updated based on notes in 1 above).
When the member clicks to view all hours and miles, this is displayed (read-only).
Ideally, I'd like total hours and total miles for whatever period they select to display with or below the table.
Thanks in advance for any help you can provide.
Another attempt using the ID of the input field (which is connected to the data item loginEmail):
import wixUsers from 'wix-users'; // ... let user = wixUsers.currentUser; let userId = user.id; let isLoggedIn = user.loggedIn; let userRole = user.role; user.getEmail() .then( (email) => { let userEmail = email; // "user@something.com" let input27 = userEmail; } );
No errors but the user's email is not entered into input27. I know it has to be something easy but I can't figure it out. Should I be using an export command?
Another question about defaulting the login user's email address? Could/should this be a data hook? If so, can you help me with the code for that?
While waiting for answers to my questions, I'm trying to create summaries for the table. Here is my code but I keep getting parsing error so I can't test whether anything is calculating. Anyone able to help me?
import wixData from 'wix-data'; //attempting to sum total hours and total miles for the table (which is filtered by Owner) $w.onReady(function () { $w("#table2").columns = [ { "id": "col1", "dataPath": "hours", "label": "Hours", "type": "number" }, { "id": "col2", "dataPath": "miles", "label": "Miles", "type": "number" }, ] //TODO: write your page related code here... }); wixData.aggregate("Hours") .sum("hours") .run() .then( (results) => { if (results.items.length > 0) { let items = results.items ; } ; wixData.aggregate("Miles") .sum("miles") .run() .then( (results) => { if (results.items.length > 0) { let items = results.items ; } ; let newAggregateH = aggregate.sum("hours", "sumHours"); //aggregate hours let newAggregateM = aggregate.sum("miles", "sumMiles"); //aggregate miles //Parsing error, unexpected token
Once this is working, I'm unclear about how to display the totals on the page. Will it create a row in the table for totals?
A different approach to creating totals for my table. It doesn't have any parsing errors but doesn't display my totals as expected:
//attempting to sum total hours and total miles for the filtered dataset EDITMilesHoursLog (filtered by login user/owner) //aggregate (total) hours and miles wixData.aggregate("EDITMilesHoursLog") .sum("hours", "miles") .run() .then( (results) => { let hours = results.items.hours ; let miles = results.items.miles; $w('#TotalHours').value = hours; //this is the field I want to display the total hours $w('#TotalMiles').value = miles; // this is the field I want to display the total miles } );
Wondering if anyone else has attempted to display totals for a filtered table? (In this case, it is filtered by the user who entered it on a member-only page. This seems like pretty basic functionality for tables and data bases so I'm puzzled by why it is so difficult.
Barb