Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ability to use static data (no server-side)#221

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
OzanKurt wants to merge2 commits intoyajra:master
base:master
Choose a base branch
Loading
fromOzanKurt:master

Conversation

OzanKurt
Copy link
Contributor

@OzanKurtOzanKurt commentedAug 8, 2024
edited
Loading

I recently wanted to use the package for a "array based datatable".

Sadly when I do;

{!!$dataTable->table()!!}

it doesn't generate the tables body.

I added some logic to theBuilder class so that we can make it fill thetbody IF theserverSide option is disabled.

Here is an example DataTable I've prepared along with 2 methodsmakingRowExample andmakingCellExample explaining how theRow andCell classes apis work. I tried to make things similar to theColumn class which we already.

There area a couple important places I've marked via comments inside the code.

<?phpnamespaceApp\DataTables;useApp\DataTables\Core\Html\Column;useApp\Models\User;useYajra\DataTables\Html\Builder;useYajra\DataTables\Html\Cell;useYajra\DataTables\Html\Row;useYajra\DataTables\Services\DataTable;class ExampleStaticDataTableextends DataTable{// IMPORTANT:// You can name this method whatever you want, it will simply allow you to populate the rows datapublicfunctionbuildRows()    {$users = User::query()->get();$rows = [];/** @var User $user */foreach ($usersas$user) {$rows[] = ['full_name' =>$user->full_name,'email' =>$user->email,'created_at' =>$user->created_at?->format('Y-m-d H:i:s') ??'N/A',            ];        }return$rows;    }// IMPORTANT:// Here we call the `rows(array $rows = [])` method on the `Builder` instance// set the `serverSide` attribute to `false`publicfunctionhtml():Builder    {return$this            ->builder()            ->rows($this->buildRows())            ->serverSide(false);    }publicfunctiongetColumns():array    {return [            Column::make('full_name'),            Column::make('email'),            Column::make('created_at'),        ];    }// IMPORTANT:// Example usages of the Row apipublicfunctionmakingRowExample()    {// Option 1://      If your row doesn't have any attributes,//      you can directly use array for its cells.$rowExample1 = [// Cells here...        ];// Option 2://      If your row has attributes,//      you must put the cells to the `cells` key.$rowExample2 = ['row-class' =>'gray-row','cells' => [// Cells here...            ],        ];// Option 3://      If your row has no attributes,//      leave the first parameter as an empty array.$rowExample3 = Row::make(['row-class' =>'gray-row',        ], [// Cells here...        ]);$rowExample4 = Row::make(['row-class' =>'gray-row',        ])->cells([// Cells here...        ]);    }// IMPORTANT:// Example usages of the Cell apipublicfunctionmakingCellExample()    {// Option 1 - Directly inside Row array as `key => value` pairs$cellExample1_1 = ['column_1' =>'Column #1 Content','column_2' =>'Column #2 Content',        ];$cellExample1_2 = ['cells' => ['column_1' =>'Column #1 Content','column_2' =>'Column #2 Content',            ],        ];// Option 2 - Using array$cellExample2 = ['column' =>'column_1','content' =>'Column #1 Content',        ];// Option 3 - Using Cell Object$cellExample3_1 = Cell::make('column_1','Column #1 Content');$cellExample3_2 = Cell::make('column_1')->content('Column #1 Content');    }}

yajra reacted with thumbs up emojiyajra reacted with heart emojiArne1303 reacted with eyes emoji
@OzanKurt
Copy link
ContributorAuthor

Hello@yajra ,

Could you please have a look at this and share me your feedback?

Here I also added the basic usage of the datatable for the controller and the blade parts.

class TestControllerextends Controller{publicfunctiontest()    {$dataTable =newExampleStaticDataTable();returnview('test')->with(['dataTable' =>$dataTable->html(),        ]);    }}
{!!$dataTable->table()!!}{!!$dataTable->scripts()!!}

@1190
Copy link

hey@yajra, could you please review this?

@OzanKurtOzanKurt marked this pull request as ready for reviewAugust 11, 2024 00:32
@yajra
Copy link
Owner

@OzanKurt this is a great feature, thanks for sending the PR. I will test this as soon as I can.

One thing I noticed is that maybe we can simplify the syntax further by settingserverSide: false by default when rows are used.

publicfunctionhtml():Builder    {return$this            ->builder()            ->rows($this->buildRows()) -- callingthis will set serverSide to false            ->serverSide(false); -- so we can removethis line    }

Co-authored-by: Arjay Angeles <aqangeles@gmail.com>
@sonarqubecloudSonarQubeCloud
Copy link

@OzanKurt
Copy link
ContributorAuthor

Automatically calling serverSide(false) makes so much sense!

In addition to this I am currently working on the option to load the initial data from ajax while havingserverSide(false).

I will send a new update in a couple days.

@yajra
Copy link
Owner

Thanks for the updates, let me know if this is ready for review again.

@yajrayajra marked this pull request as draftAugust 17, 2024 04:58
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@yajrayajrayajra requested changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@OzanKurt@1190@yajra

[8]ページ先頭

©2009-2025 Movatter.jp