Each time I replace the data in #repeater it merges the old data with the new data…
I’m certain this is not occurring in the backend function crm.cities.
I’m not sure why this is happening, really need help with this.
Btw, ctas() purpose is to split the array results of crm.cities into a range of objects on button click. AKA next and previous buttons for a repeater with large ammount of items.
import { local } from ‘wix-storage’ ;
import * as crm from ‘backend/CRM.jsw’ ;
let fadeOptionsHide = { “duration” : 200 }
let fadeOptionsShow = { “duration” : 300 , “delay” : 500 }
//For backend processing
let userInput ;
let RANGE = “A2:R” ;
let resultsPerPage ;
let arrayRange = { min : 0 , max : 0 };
$w . onReady ( function () {
userInput = $w ( “#cityFilter” ). value ;
resultsPerPage = Number ( $w ( “#pageCountDropdown” ). value );
arrayRange . max = resultsPerPage ;
repeaterDataRun ();
$w ( "#cityFilter" ). onChange (( event ) => {
userInput = $w ( "#cityFilter" ). value ;
arrayRange . max = resultsPerPage ;
arrayRange . min = 0 ;
repeaterDataRun ();
})
});
function repeaterDataRun ( ) {
$w ( ‘#repeater’ ). data = [];
//Call to backend processing
crm . cities ( userInput , RANGE )
. then (( results ) => {
$w ( ‘#repeater’ ). data = results . slice ( arrayRange . min , arrayRange . max );
$w ( “#pageCount” ). text = "Page " + arrayRange . max / resultsPerPage + " of " + String ( Math . ceil ( results . length / resultsPerPage ));
$w ( "#repeater" ). onItemReady (( $item , itemData , index ) => {
$item ( "#fullName" ). text = itemData . firstName + " " + itemData . lastName ;
})
ctas ( results );
$w ( "#totalObjects" ). text = "Results: " + String ( results . length );
//Show if logged-in
$w ( "#repeater" ). show ( "fade" , fadeOptionsShow );
$w ( "#next" ). show ( "fade" , fadeOptionsHide );
$w ( "#cityFilter" ). show ( "fade" , fadeOptionsHide );
$w ( "#pageCountDropdown" ). show ( "fade" , fadeOptionsHide );
$w ( "#previous" ). show ( "fade" , fadeOptionsHide );
$w ( "#totalObjects" ). show ( "fade" , fadeOptionsHide );
$w ( "#pageCount" ). show ( "fade" , fadeOptionsHide );
//Hide if logged-in
$w ( "#loading" ). hide ( "fade" , fadeOptionsHide );
})
//REMEMBER TO CATCH ERROR IN CASE NO DATA IN SHEET
}
function ctas ( results ) {
$w ( “#next” ). onClick (( event ) => {
//Current Page < Total Pages
if (( arrayRange . max / resultsPerPage ) < Math . ceil ( results . length / resultsPerPage )) {
arrayRange . max += resultsPerPage ;
arrayRange . min += resultsPerPage ;
$w ( “#pageCount” ). text = "Page: " + ( arrayRange . max / resultsPerPage ) + " of " + Math . ceil ( results . length / resultsPerPage );
$w ( ‘#repeater’ ). data = results . slice ( arrayRange . min , arrayRange . max );
}
})
$w ( "#previous" ). onClick (( event ) => {
//Current Page > 1
**if** (( arrayRange . max / resultsPerPage ) > 1 ) {
arrayRange . max -= resultsPerPage ;
arrayRange . min -= resultsPerPage ;
$w ( "#pageCount" ). text = "Page: " + ( arrayRange . max / resultsPerPage ) + " of " + Math . ceil ( results . length / resultsPerPage );
$w ( '#repeater' ). data = results . slice ( arrayRange . min , arrayRange . max );
}
})
$w ( "#pageCountDropdown" ). onChange (( event ) => {
resultsPerPage = Number ( $w ( "#pageCountDropdown" ). value );
arrayRange . max = resultsPerPage ;
arrayRange . min = 0 ;
$w ( "#pageCount" ). text = "Page: " + ( arrayRange . max / resultsPerPage ) + " of " + Math . ceil ( results . length / resultsPerPage );
$w ( '#repeater' ). data = results . slice ( arrayRange . min , arrayRange . max );
})
}