I have a table with 3 pages and I would like to have a script that can calculate the total rows from these 3 pages and put it in the TEXT box as shown in the link here
https://www.mascusa.com/renewal-membership-test
Any help will be greatly appreciated.
@hlaw please check your "});" syntax some are missing and your variable names are not the same as declared above. wixData.query("paymentForm01") .count() .then( (num) => { let TotalRegularMembers= num; wixData.query("paymentForm012") .count() .then( (num2) => { let TotalSilverMembers= num2; wixData.query("paymentForm013") .count() .then( (num3) => { let TotalPlatinumMembers= num3; wixData.query("StudentMembership") .count() .then( (num4) => { let TotalStudentMembers= num4; let grandtotal = TotalRegularMembers + TotalSilverMembers + TotalPlatinumMembers + TotalStudentMembers; $w("#REDTEXT").text = grandtotal.toString(); }); }); }); } );
@hlaw or you can do something like this import wixData from 'wix-data'; wixData.query("yourCollectionName") .count() .then( (num) => { let allResults = num; $w("#TotalRenewalMembers").text = allResults.toString(); } ); --- It will count the total rows on your collection database. https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#count
@hlaw There's several ways to do it. This way will return the desired result whether you are using a dataset to populate the table or otherwise. Having the code inside the onReady function for the page and dataset assures that the page elements and dataset is fully loaded before trying to run any functions. If you are not using a dataset, you can remove the second onReady pertaining to the dataset and a set of closing braces/parenthesis.
$w.onReady(function () { $w('#dataset1').onReady(() => { let recs = $w("#table1").rows.length; $w("#RenewalMembers").text = recs.toString(); }); });