setPageSize

I have the following code which uses the setPageSize for my repeater to display 1 item. If there is more than 1 item then the LOAD MORE (button3) shows. If a user selects the LOAD MORE and then changes the dropdown3 value, the repeater doesn’t reset the setPageSize back to 1. If the user pressed the LOAD MORE 2 more times to display 3 items, when they change the dropdown3 value to something else the repeater doesn’t reset the setPageSize back to 1 it will use the 3 instead.

Any insight to how to correct this so that each time the user changes the dropdown3 value, the setPageSize will also reset to 1?

export function dropdown3_change(event) {
var maxShow = 1 ;
$w( “#dataset2” ).setPageSize(maxShow);
console.log(maxShow);

 $w( "#dataset2" ).setFilter(wixData.filter() 
        .eq( "platform" ,$w( "#dropdown3" ).value) 
        .ne( "hide" , **true** ) 
) 
    .then(() => { 

let totalCount = $w( “#dataset2” ).getTotalCount();
//console.log(totalCount);
if ( totalCount > maxShow) {
$w( “#button1” ).show();
}
else {
$w( “#button1” ).hide();
}
});

}

To add to this, in doing a console.log, the setPageSize is resetting to 1, but the data is still pulling 3. It seems the repeater is ignoring the setPageSize value after the initial page load.

Try this one. And next time → please use CODE-TAGs for CODE-SNIPETS! :wink:

I do not know if this will work, but give it a try :grin:

export function dropdown3_change(event) {
    setTimeout(()=>{
        let maxShow = 1;
        xxx(maxShow)
    },50)
}


function xxx (maxShow) {console.log(maxShow);
    $w("#dataset2").setPageSize(maxShow);    

    $w("#dataset2").setFilter(wixData.filter()
        .eq("platform",$w("#dropdown3").value)
        .ne("hide",true)
    )
 
    .then(() => {
        let totalCount = $w("#dataset2").getTotalCount();     
        console.log(totalCount);

        if ( totalCount > maxShow) {$w("#button1").show();}   
        else {$w("#button1").hide();}
    });
}

Thanks for the tip on the CODE SNIPPET…will do next time.

Tried your code but same results. Repeater is pulling more than the 1 if the user has selected the LOAD MORE.

@scottb
I do not see any CODE for LOAD-MORE-BUTTON in your snipet !?!?
So if you have connected your DATASET and are using the optional integrated next/previous-buttons and load-more button, then this will probably not work as you want.

You will have to CODE it by yourself, to get it working like you want.

Mixing CODE with integrated DATASET-options, always have a bad end!:wink:

@russian-dima Yes my load-more button is tied to the dataset. So I tried this, but same results. The total number displayed is not resetting to 1.

import wixData from "wix-data";

export function dropdown3_change(event) {
    setTimeout(()=>{
 let maxShow = 1;
        xxx(maxShow)
    },50)
}


function xxx (maxShow) {console.log(maxShow);
    $w("#dataset2").setPageSize(maxShow);    

    $w("#dataset2").setFilter(wixData.filter()
        .eq("platform",$w("#dropdown3").value)
        .ne("hide",true)
    )
 
    .then(() => {
 let totalCount = $w("#dataset2").getTotalCount();     
        console.log(totalCount);

 if ( totalCount > maxShow) {$w("#button1").show();}   
 else {$w("#button1").hide();}
    });
}

export function button1_click(event) {
    $w("#dataset2").loadMore();
}

Perhaps…

import wixData from "wix-data";

$w.onReady(()=>{
   $w("#dataset2").onReady(()=>{
      $w('#dropdown3').onChange((event)=>{
         setTimeout(()=>{
            let maxShow = 1;
            xxx(maxShow)
         },50)
      })
      
      $w('#button1').onClick(()=>{
         $w("#dataset2").loadMore();
      })
   })
})


async function xxx (maxShow) {console.log(maxShow);
    await  $w("#dataset2").setPageSize(maxShow);    
    $w("#dataset2").setFilter(wixData.filter()
        .eq("platform",$w("#dropdown3").value)
        .ne("hide",true)
    )
 
    .then(() => {
 let totalCount = $w("#dataset2").getTotalCount();     
        console.log(totalCount);

 if ( totalCount > maxShow) {$w("#button1").show();}   
 else {$w("#button1").hide();}
    });
}

Same bad results…setPageSize is not being updated/reset when the user changes the dropdown selection. I do appreciate the efforts so far though!