Hi Folks. I have a statistics page showing how many centers I have trained and the total trainings for all centers together. Now I need to get the individual center totals. Each center that had training is listed once. I need the individual totals to go in the red circle in the pic. I’m working with 2 datasets. One with the centers (#centerData / centers ) and one with the trainings (#dynamicDataset / training_progrss ). I’ve put my code below for the entire page. Any help with this is greatly appriciated.
import { local } from ‘wix-storage’ ;
import wixData from ‘wix-data’ ;
import wixWindow from ‘wix-window’ ;
import wixLocation from ‘wix-location’ ;
import wixUsers from ‘wix-users’ ;
let fadeOptions = {
“duration” : 0 ,
“delay” : 3000
};
export function dynamicDataset_ready() {
$w( “#dynamicDataset” ).setFilter(wixData.filter()
.contains( “trainer” , ‘XXXX’ )
)
.then(() => {
console.log( "Dataset is now filtered" );
})
. **catch** ((err) => {
console.log(err);
});
}
export function filter_click(event, $w) {
$w( “#count” ).show();
$w( “#centers” ).show();
$w( “#centersRepeater” ).show();
wixData.query( 'training_progrss' )
.contains( 'trainer' , $w( "#staff" ).value)
.lt( 'training_date' , $w( '#toDate' ).value)
.gt( 'training_date' , $w( '#fromDate' ).value)
.count()
.then((num) => {
$w( "#count" ).text = '' + num;
});
wixData.query( 'training_progrss' )
.contains( 'trainer' , $w( "#staff" ).value)
.lt( 'training_date' , $w( '#toDate' ).value)
.gt( 'training_date' , $w( '#fromDate' ).value)
.distinct( 'center_id' )
.then((num2) => {
$w( "#centers" ).text = '' + num2.totalCount;
});
wixData.query( 'training_progrss' )
.include( 'center_id' )
.contains( 'trainer' , $w( "#staff" ).value)
.lt( 'training_date' , $w( '#toDate' ).value)
.gt( 'training_date' , $w( '#fromDate' ).value)
.descending( 'training_date' )
.find()
.then((results) => {
let items = results.items;
items = items.filter((e, i) => items.findIndex(q => q.center_id.title === e.center_id.title) === i);
$w( '#centersRepeater' ).data = items;
$w( "#centersRepeater" ).onItemReady(($item, itemData) => {
$item( "#center" ).text = itemData.center_id.title;
$item( "#url" ).text = itemData.center_id.subdomain;
$item( "#link" ).link = itemData.center_id.subdomain;
// $item(“#centerTrainings”).text = ‘’ + itemData.center_id.title.totalCount; // this just shows the same number for all
console.log(itemData.center_id.title);
})
})
}
export function reset_click(event, $W) {
$w( “#dynamicDataset” ).setFilter(wixData.filter()
.contains( “trainer” , ‘XXXX’ ))
$w( “Staff” ).value = “Filter by Staff”
$w( “#centersRepeater” ).hide();
$w( “#count” ).text = ‘0’ ;
$w( “#centers” ).text = ‘0’ ;
$w( “#count” ).hide();
$w( “#centers” ).hide();
$w( “#fromDate” ).value = new Date();
$w( “#toDate” ).value = new Date();
}
