© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
25 replies
Mohammed Ouda

Select Component Lazy Loading though API

I use external API as the source of options for my select component.

Is there anyway to make it support the pagination of the api? which means load more data once the user scrolled to the end of shown records? either by auto calling the api and pass param page=1/2/3.. or the user click on show more button or smth' similar?

My current code:

here is how i use the component:
Select::make('general_topic_id')
                            ->label('General topic')
                            ->searchable()
                            ->options(fn ($get) => $this->getGeneralTopicOptions($get, null))
                            ->getSearchResultsUsing(fn ($get, string $search) => $this->getGeneralTopicOptions($get, $search))
                            ->disabled(fn ($get) => !$get('org_library_access_authorization_id'))
                            ->reactive()
                            ->placeholder('Select a general topic'),
Select::make('general_topic_id')
                            ->label('General topic')
                            ->searchable()
                            ->options(fn ($get) => $this->getGeneralTopicOptions($get, null))
                            ->getSearchResultsUsing(fn ($get, string $search) => $this->getGeneralTopicOptions($get, $search))
                            ->disabled(fn ($get) => !$get('org_library_access_authorization_id'))
                            ->reactive()
                            ->placeholder('Select a general topic'),


and here is my getGeneralTopicOptions method:
private function getGeneralTopicOptions($get, $search): array
    {
        $orgLibraryAccessAuthorizationId = $get('org_library_access_authorization_id');
                        
        if (empty($orgLibraryAccessAuthorizationId)) {
            return [];
        }

        $generalTopics = ReferenceCurriculumService::getGeneralTopics($orgLibraryAccessAuthorizationId, $this->course->subject_code, $search);

        return collect($generalTopics)->mapWithKeys(function ($topic) {
            return [$topic['id'] => $topic['name']];
        })->toArray();
    }
private function getGeneralTopicOptions($get, $search): array
    {
        $orgLibraryAccessAuthorizationId = $get('org_library_access_authorization_id');
                        
        if (empty($orgLibraryAccessAuthorizationId)) {
            return [];
        }

        $generalTopics = ReferenceCurriculumService::getGeneralTopics($orgLibraryAccessAuthorizationId, $this->course->subject_code, $search);

        return collect($generalTopics)->mapWithKeys(function ($topic) {
            return [$topic['id'] => $topic['name']];
        })->toArray();
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Lazy loading for Select form component options
FilamentFFilament / ❓┊help
2y ago
select filter lazy loading
FilamentFFilament / ❓┊help
2y ago
Lazy loading Select ->preload()
FilamentFFilament / ❓┊help
3y ago
Lazy Loading Infolist Entry?
FilamentFFilament / ❓┊help
2y ago