I wrote this function but I have a problem.
When I display the dropdown with page (1,2,3) and every page has 5 products. It does not display the next 5 products when I click on the number 2 of the dropdown but it comme back on the index page.
I think this element : PAGESETGOTO
do not take the good page value of th dropdown and there is maybe a problem with the javascript
Do you have any idea how to resolve this ?
TK
public function getPageSetLinks($parameters = null, $site = null)
{
$number_of_pages = ceil($this->page_set_total_rows / $this->page_set_results_per_page);
if (empty($parameters)) {
$parameters = '';
}
if (!empty($parameters)) {
parse_str($parameters, $p);
if (isset($p[$this->page_set_keyword])) {
unset($p[$this->page_set_keyword]);
}
$parameters = !empty($p) ? http_build_query($p) . '&' : '';
}
$pages = [];
for ($i = 1; $i <= $number_of_pages; $i++) {
$pages[] = [
'id' => $i,
'text' => $i
];
}
$output = '<nav aria-label="pagination">';
$output .= '<ul class="pagination pagination-sm">';
if ($number_of_pages > 1) {
--
-- the line for the dropdown
$output .= '<li class="page-item">' . HTML::selectField('pageset' . $this->page_set_keyword, $pages, $this->page_set, 'style="vertical-align: top; display: inline-block; float-md-left; height: 32px; width: 80px;" data-pageseturl="' . HTML::output($this->link(null, $parameters . $this->page_set_keyword . '=PAGESETGOTO')) . '"') . '</li>';
} else {
$output .= '<li class="page-item disabled"><a class="text-md-center page-link sr-only">1</a></li>';
}
$output .= '</ul>';
$output .= '</nav>';
if ($number_of_pages > 1) {
$output .= <<<EOD
<script>
$(function() {
$('select[name="pageset{$this->page_set_keyword}"]').on('change', function() {
window.location = $(this).data('pageseturl').replace('PAGESETGOTO', $(this).children(':selected').val());
});
});
</script>
EOD;
}
return $output;
}