question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] select2_ajax filter and select2_from_ajax field pagination not working

See original GitHub issue

Bug 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:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tabacitucommented, Jun 28, 2022

@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.

1reaction
kartomantascommented, Dec 13, 2022

@pxpm I am using “backpack/pro”: “^1.2”. Also, I have zero overwritten filters in my resources folder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pagination not working in select2 plugin - Stack Overflow
I am using select2 plugin. All are working well. but pagination is not working. Showing "Loading more results" at the end & it's...
Read more >
Select2 Ajax jquery load data, but doesn't filter the results
Hi, I've achieved to load data from a REST webservice, but results are not filtered when I write a query in the search...
Read more >
Select2 with Pagination to improve loading time - DataTables
There's no reason why it shouldn't work - it's just a select2 control within the table's element. You would need to ensure the...
Read more >
Examples - Select2 - JeeSite
A placeholder value can be defined and will be displayed until a selection is made. Select2 uses the placeholder attribute on multiple select...
Read more >
Changelog - ACF
Enhancement - Added "acf/admin/license_key_constant_message" filter to ... Fix - Fixed bug causing incorrect Repeater field value order in AJAX requests.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found