[Bug] select2_ajax filter and select2_from_ajax field pagination not working
See original GitHub issueBug report
What I did
Created a select2_ajax filter:
return $crud->addFilter([
'name' => $name,
'type' => 'select2_ajax',
'label' => __('admin.'.$name),
'select_attribute' => $attribute,
'method' => 'POST',
'minimum_input_length' => 0
], $fetchUrl,
function ($value) use ($name, $crud) {
$crud->addClause('where', $name, $value);
});
$fetchUrl returns:
protected function fetchThis()
{
return $this->fetch([
'model' => $this->crud->model,
'query' => function($model) {
return $model->orderBy('id', 'DESC');
},
'paginate' => 5
]);
}
What I expected to happen
I have thousands of records in my database so I expected my select2 field to dynamically paginate results 5 by 5 with infinite scroll (https://select2.org/data-sources/ajax#pagination).
What happened
Select2 field always returns only 5 results. There’s no infinite scrolling to load additional results.
What I’ve already tried to fix it
I also tried it with select2_from_ajax field type. It doesn’t work. If ajax field can’t dynamically load paginated results, what’s the difference between simple select from array and select2_from_ajax…? As I understand, the best use case for ajax loading is when you have lots of results so you load them dinamically in order not to overload your DOM and decrease website loading time. Now when it works like that as it is now, there is no purpose to use select2_from_ajax…
Is it a bug in the latest version of Backpack?
After I run composer update backpack/crud
the bug… is it still there? YES.
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version
the output is:
php artisan backpack:version
### PHP VERSION:
PHP 8.0.6 (cli) (built: May 4 2021 23:31:45) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.6, Copyright (c) Zend Technologies
### LARAVEL VERSION:
v9.15.0@dc32641f5963578858fb71a9d2fbf995fe1e1ea3
### BACKPACK VERSION:
5.0.20@a6b183978fc7c206ce9cd437e5c9b96f8fb6823f
Process finished with exit code 0.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
@kartomantas I’ve just merged @maurohmartinez 's PR, which fixes this problem. Starting Monday, when we tag a new version, the fix will be available with a
composer update
🎉 So I’m going to close the issue. If you’re still having problems after that, please let us know here and we’ll gladly reopen.Cheers! Thanks for reporting this, and thanks @maurohmartinez for the fix.
@pxpm I am using “backpack/pro”: “^1.2”. Also, I have zero overwritten filters in my resources folder.