Skip to content

feat: TableBuilder lazy #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2024
Merged

Conversation

lee-to
Copy link
Member

@lee-to lee-to commented Sep 30, 2024

TableBuilder::make()
    ->name('dashboard-table')
    ->fields([
        ID::make(),
        Slug::make('Slug'),
        Text::make('Title'),
        Preview::make('Image')->image()
    ])
    ->async()
    ->lazy()
    ->whenAsync(
        fn(TableBuilder $table) => $table->items(
            Http::get('https://jsonplaceholder.org/posts')->json()
        )
    ),

@ArtemYurov
Copy link
Contributor

В таком виде всё работает так, как должно работать.
Если кеш пустой или expired, то lazy загрузка происходит.
По кнопке обновить - загружает свежие данные

            ActionButton::make('Обновить')
                ->async(events: [AlpineJs::event(JsEvent::TABLE_UPDATED, self::MAIN_TABLE_NAME)]),

            TableBuilder::make()
                ->name(self::MAIN_TABLE_NAME)
                ->fields($this->tableFields())
                ->async(events: [AlpineJs::event(JsEvent::FRAGMENT_UPDATED,self::UPDATED_TIME_NAME)])
                ->items($cachedItems)
                ->when(
                    empty($cachedItems) || $expiredTime,
                    fn(TableBuilder $table) => $table->lazy()
                )
                ->whenAsync(
                    fn(TableBuilder $table) => $table->items($this->updateTableItems())
                )
                ->withNotFound()
                ->sticky()
                ->when(
                    $this->totalSumRowColumns,
                    fn($table) => $table->totalSumRow($this->totalSumRowColumns)
                )
                ->simple()
                ->addAssets([InlineCss::make('.table-sticky { max-height: 85dvh; }')])

@lee-to lee-to merged commit f87f1b3 into moonshine-software:3.x Oct 2, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants