Paging in Result page

Paging in Result page.

I need help to run paging repeater when they get data from dataset after query database.

mycode:

function searchProduct () {

wixData.query(‘Stores/Products’)
.contains(‘name’,$w(‘#input1’).value)
//.or(wixData.query(‘Stores/Products’).contains(‘description’, $w(‘#input1’).value))
.find()
.then( res => {
$w(‘#alert’).text=“Searching data”
$w(‘#repeater1’).data=res.items;
$w(‘#alert’).text= “Found “+ $w(‘#repeater1’).data.length.toString() +” result with keyword " +'”‘+ $w(’#input1’).value+‘"’;

        $w('#repeater1').show(); 
        $w('#box1').show(); 
        $w('#box1').expand(); 
        $w('#box2').collapse(); 
 
    $w('#mes').text=curentPage.toString(); 
    }) 

//$w(‘#pagination1’).totalPages=resultPage;

// show this value in the textbox

}

my DataSet name is ProductList. I connected repeater1 to ProductList. Everything is fine but I need help paging by code.

thanks

Still need help

Hi tuannq6886,

You can do it with simpler code by setting a filter for your DataSet and binding it on a repeater. Then you can have a button on your site which would ask for next page from DataSet.

Here is an example:

function searchProduct() {
    const filter = wixData.filter().contains('description', $w('#input1').value))
    $w('#ProductList').setFilter(filter)
    $w('#ProductList').refresh()
    $w('#repeater1').show()
}

function nextPage() {
    $w('#ProductList').nextPage()
}

You can read some more on how to control your dataset through code here.

Let me know if that works for you.

Thanks for support. Simple code for query shoulbe by use filter like your code.
But i try to make a paging by numbe page, for example: 1,2,3…next

Can you tell me make a function for them?

Oh the other thing happeing with getTotalCount() of dataset,
the first result equal total item in datase
the second result (after click search button) is the equal exactly number of record in data
but the third and next time click the result of total item equal zero

Here is my code

function searchProduct () {

const filterProduct = wixData.filter().contains(‘name’,$w(‘#input1’).value) ;
let numPage ;

        $w('#alert').text="Đang tìm kiếm dữ liệu" 
            $w('#ProductList').setFilter(filterProduct); 
            $w('#ProductList').refresh(); 

//
$w(‘#mes3’).text=$w(‘#ProductList’).getTotalCount() ;
// $w(‘#alert’).text= “Found “+ $w(‘#ProductList’).getTotalCount() +” result for keyword " +'”‘+ $w(’#input1’).value+‘"’;
$w(‘#box1’).show();
$w(‘#repeater1’).show();
$w(‘#box1’).expand();
$w(‘#box2’).collapse();

//$w(‘#pagination1’).totalPages=resultPage;

// show this value in the textbox

}

the first click: alert=total item in my data
the second click: alert= item after query (Right number)
the third click : alert=0;
How can i solve them?