vue-good-table
vue-good-table copied to clipboard
on-per-page-change is called twice if perPage is set following the first event
Issue Type (delete the irrelevant ones)
- [x] Bug
Specs
What version are you using?
- 2.21.11
What browser?
- Firefox 97.0 for Windows
Expected Behavior
Even if the event listener for @on-per-page-change sets the value that's assigned to perPage, especially not to the same value, it should only trigger the event once.
Actual Behavior
It behaves like a watcher for some reason. It's fired once when the user changes the number of items per page, and once again when GET parameters are updated following the event.
The watcher seems to be here:
https://github.com/xaksis/vue-good-table/blob/889962c5b67f5bb621caa0a9bf0b3852d4199235/dist/vue-good-table.esm.js#L2411
I'm not sure what the solution is, but I've got a strong feeling that changing the props on my side shouldn't trigger a feedback loop like this.
Steps to Reproduce the Problem
Please detail your steps here
- Change the number of items per page while keeping a close eye on the console
- See that
onPerPageChangeis fired twice. - On HTML's line 20, use
DEFAULT_API_GET_DATA_PARAMS.perPageinstead. - Now
onPerPageChangeis only fired once.
An alternative workaround would be to run a for...in loop on all paramsToSet in setApiGetParamsAndFetchRows and, for each parameter, compare it to the current value and only change it if it's different.
...But whichever workaround you choose, it's still really weird that the event is triggered twice if you do things normally.
jsfiddle
https://jsfiddle.net/dywr30ek/17/