Hello wix Forum! I was trying to use the .setPageSize() function, to change the number of items to display of my dataset. I read in the documentation that this function can modify this value.
After several failing attempts I decided to try the code in a clean page, I copied the example code in the APi documentation and added a .getPageSize() to see if the change was happening. here is the code:
$w.onReady(function () {
//TODO: write your page related code here...
$w("#dataset1").setPageSize(6)
.then( () => {
console.log("Page size set.");
} )
.catch( (err) => {
let errMsg = err.message;
let errCode = err.code;
} );
let val = $w('#dataset1').getPageSize()
console.log(val)
});
I run it various times and it didn't worked.
I read in the documentation that:
"Calling setPageSize() on a read-only dataset causes an error."
so I checked with my dataset and it was set to "read-only" by default but it doesn't give an error, but I noticed that it does gives an error when you set the dataset to "write-only". I think that maybe they put "read-only" instead of "write only" by mistake in the documentation.
but the real problem is why .setPageSize() doesn't work, is it a bug? am I doing something wrong? if so please explain to me the right way to use this function because I really need it for my page.
below is a video showing what I did.
thanks in advance.
Hi Fausto, I see the problem in your code. You have:
$w("#myDataset").setPageSize(6) .then( () => { console.log("Page size set."); } ) .catch( (err) => { let errMsg = err.message; let errCode = err.code; } ); let val = $w("#myDataset").getPageSize(); console.log(val);
The problem is the last 2 lines are outside the .then( ) function. Because setPageSize( ) returns a Promise, which is asynchronous, the code inside .then( ) only executes after it is completed. But your last 2 lines actually end up executing before setPageSize( ) has completed! That's why the output in the console is reversed (first you see "20" and then you see "Page size set.").
To solve this, move the last 2 lines of code inside the .then( ) function code, and it should work. Hope this helps!
Hi @a.bronson, your code is getting `Dropdown.value`, which returns a string, and attempting to use that to set the dataset's pageSize, which requires a number. You'll have to convert the string to a number and then use that. Hope this helps.
also i see nothing in console, nor the log or error report
i can set the page size from buttons, but i can't set the page size from user input elements, i've tried text input and dropdown, i even using substr(0,1) for the value, but still no luck
is it not fixed yet or is there an error on my code ?
here's my code
export function dropdown1_change(event) { $w("#dataset1").setPageSize($w('#dropdown1').value) .then(() => { console.log("Page size set."); }) .catch((err) => { let errMsg = err.message; let errCode = err.code; }); }
Oh, also, I forgot to mention: You were right about the documentation for setPageSize( ) being incorrect. I notified our technical writer and it will be fixed soon. Thanks for letting us know!
thanks a lot Chaim! this solved the problem in this code, now I will see if it also works on my page.
thanks Roi.
Hi,
We are inspecting this issue at this moment.
Roi.