GithubHelp home page GithubHelp logo

rappasoft / laravel-livewire-tables Goto Github PK

View Code? Open in Web Editor NEW
1.7K 37.0 314.0 2.31 MB

A dynamic table component for Laravel Livewire

Home Page: https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction

License: MIT License

PHP 71.12% Blade 16.05% CSS 10.14% JavaScript 2.69%
laravel-livewire laravel datatables livewire livewire-tables

laravel-livewire-tables's People

Contributors

abdosaeedelhassan avatar adamwoodhead avatar bdelamatre avatar bomshteyn avatar cristhofermf avatar cubemastercodes avatar devsrv avatar dgillier avatar enaah avatar fabio-ivona avatar iamkevinmckee avatar inmanturbo avatar izzyp avatar juliomotol avatar jyrkidn avatar kaulse avatar kenlewis avatar lloricode avatar lrljoe avatar macbookandrew avatar majkie avatar marcheffels avatar nessimabadi avatar rappasoft avatar simonmacintyre avatar sotten avatar tobiashammarstrand avatar tonypartridge avatar whereislucas avatar ypho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-livewire-tables's Issues

label's can't be overwritten directly

In your readme it says You can override any of these in your table component:

however,

$this->setTranslationStrings();

overwrites the properties in constructor. So normal overwrites don't work and you have to do something like:

    public function __construct($id)
    {
        parent::__construct($id);
        $this->noResultsMessage = '一致するレコードがありません';
        $this->perPageLabel = '件表示';
    }

I can see why you need to do it like that, but it might be worth mentioning in the readme.

how to create the serial number colum

able data is for multiple users and multiple users are interesting the data in the database but when you show it to the user to look like 5,56,64 more like that which is not good
so I want to show them like the 1,2,3

Upcoming 0.3 Rebuild

I spent the last few days doing a semi-rebuild and removing some features I don't think I need right now. I need some people to test with the current development branch using the new README on that branch for guidance and report back on if you like this format better.

These are the current release points:

Added

  • Config file to choose frontend framework - currently limited to bootstrap
  • Render method to columns which returns whatever you put into it, you can return a view, html, an attribute, etc.
  • Pulled in and modified the HTML component library from laravelcollective so you an return html components from the render method. i.e.: $this->image(...);
  • Added new loading config on whether to keep displaying the current data while loading or collapse it
  • Added ability to set frontend framework specific options via a property on a per component basis.

Changed

  • Extracted the sorting icons out to their actual HTML, so you can use whatever you want, not limited to the 'i' tag.

Removed

  • Checkbox functionality for now
  • Component functionality pending debate
  • All class and styling based properties. It's better to publish the views to change something.

I will probably merge this to master tomorrow, do not update if you are using components or checkboxes.

How to make a row clickable?

I have certain rows that I want to be clickable (across the whole row), that redirects to a named route.

I don't want to edit the table blade directly since the route will change based on the table, and some tables wont be clickable at all.

How would I do about doing this? Thanks.

Add ability to hide a column

For now, we must create a new class that extends Column and use CanBeHidden trait but it would be great if this package has built-in support.

Changed language

when using search or sorting, the language of the page changes

Doesn't like camelCased relation names

Hi There!

If i have a relation, say, physicalAddress, laravel encodes that as physical_address in the data if you do toArray, for example.

However, your library doesn't pick that up, so if I change the column to physical_address.city, it works for display, but then sorting is broken because it looks for a relation called physical_address

Not sure if that's expected functionality or not, but wanted to make you aware of the bug.

datatable labels translation

Hi,

how to make translation for statistics under the datatable ?

1- Showing 1 to 12 out of 12 results
2- Per Page
3- Search

thank you

searching in rendered view column

i think that search operation done in model retrived data from database, but when using view in column mean that additional data added inside the column that not retrived from database, is there a way to make search operation affect in rendered view column?

Search doesn't work when page != 1

Hi, just installed to test and noticed that on the page is not the first one, the search returns no results.

Screenshot: Step 1 - Initial rendering on first page

image

Screenshot: Step 2 - Searching for "goos" on first page

Returns one row as expected.

image

But if we go to ?page=2, and search again for "goos" nothing is returned

Custom classes & attributes do not apply to header unless 'sortable' is set

Classes & attributes do not apply to headers unless they are marked as sortable.

@if($column->isSortable())
<th
class="{{ $this->setTableHeadClass($column->getAttribute()) }}"
id="{{ $this->setTableHeadId($column->getAttribute()) }}"
@foreach ($this->setTableHeadAttributes($column->getAttribute()) as $key => $value)
{{ $key }}="{{ $value }}"
@endforeach
wire:click="sort('{{ $column->getAttribute() }}')"
style="cursor:pointer;"
>
{{ $column->getText() }}
@if ($sortField !== $column->getAttribute())
{{ new \Illuminate\Support\HtmlString($sortDefaultIcon) }}
@elseif ($sortDirection === 'asc')
{{ new \Illuminate\Support\HtmlString($ascSortIcon) }}
@else
{{ new \Illuminate\Support\HtmlString($descSortIcon) }}
@endif
</th>
@else
<th>{{ $column->getText() }}</th>
@endif

Not sure of the best way to resolve other than duplicating the following:

class="{{ $this->setTableHeadClass($column->getAttribute()) }}"
id="{{ $this->setTableHeadId($column->getAttribute()) }}"
@foreach ($this->setTableHeadAttributes($column->getAttribute()) as $key => $value)
{{ $key }}="{{ $value }}"
@endforeach

font awesome icon

Unfortunately, the icons are strongly defined in the template. But I love the icons fal and not fas, it would not be bad if it would be made in the settings

How to mutate an attribute?

I store money as cents in my database. When I show it on the screen, I pass it through a money() helper that converts it to the right currency/format.

Based on the limited docs and other issues I saw that the way to accomplish this was using view() or components(). However, despite that being said, there is not an explanation of how either of these works really anywhere, and the examples given are basically duplicates of eachother so I'm not really sure what that's about?

Either way, this seems incredibly heavy handed and a lot of work for the developer to do something as basic as modifying the output.

May I give an alternative solution?

Column::make('price', function ($model) {
    return money($model->price);
}),

This is incredibly flexible and way more lightweight than this "component" system, and also way easier for developers to integrate.

Hopefully you can look into it.

pagination traverse loading

some time traversing in pagination take time according to network or size of data, is there away to let loading work also in pagination traverse, thank you

non database items

is this package applicable for non database item like reading files & rendering files from storage:disk.
i'm trying to read zipped files from storage

        $disk = Storage::disk('path to disk');

        $files = $disk->files(str_replace(' ', '-', config('backup.name')));
        $item = [];

        foreach ($files as $k => $f) {
            if (substr($f, -4) == '.zip' && $disk->exists($f)) {
                $item[] = [
                    'file_path'               => $f,
                    'file_name'               => str_replace(str_replace(' ', '-', config('backup.backup.name')).'/', '', $f),
                    'file_size_byte'          => $disk->size($f),
                    'last_modified_timestamp' => $disk->lastModified($f),
                ];
            }
        }

        $item = array_reverse($item);

        return view('backend.backup.index', compact('item'));

How to sort by pivot column?

I have a many-to-many relationship. I want to sort by a pivot field, but the normal Laravel syntax doesn't work on $sortField.
pivot.updated_at for example.

I've confirmed this does exist on my relationship in the pivot attribute, so I think this is a use-case not covered by the package.

Is it possible we could get this added. :)

view object without blade file

in columns function, is there away add view object instead of view blade file ptah, because less greating blade files for actions fileds.
thank you

opening table page after time

next error happen when device screen lock and open again after time, or browser tab swaped to other and come back after medium time
error

date casts

Not sure if it's a bug

I have a activity Model, and in the model I have this:

protected $casts = [
       'updated_at' => 'datetime',
       'created_at' => 'datetime',
       'activity_date' => 'date',
   ];

in the column is still rendered as date time and not as date only

Checkbox behavior

Hi,

While testing the "Check All" functionality, I have found a strange behavior.

I have the following table:
image

Now i activate the first three checkboxes.

What would I expect:
image

What I currently get:
image

In the dev console I can see three POST requests, which is ok - but the size and the needed time seems to be a problem:
image

Any thoughts how to solve/fix this?

Thanks!

Regards,
Marcus

Possibility to change the output

Hi,

Consider the column "primary" that is true or false. We might want to change the output to display something else instead of 0 and 1, an option that allows to display an icon, image or basicly a string that allow us to do just that. It will nice if we can include the original value in that string also, this will allow adding some icon or formating to the output text,

Cheers and very good work

search field

Hi,

search operation start before completing the search keywords, is there a way to let it start after press enter or adding search icon to click on it?

thank you

How to add classes/id to column header?

I was wondering what would be the best practice to add classes and id to a column. As you can see below, they are empty and I can't seem to find a way to populate that...

image

Component view($view) doesn't work as expected

I'm not entirely sure if this is documentation issue or I'm doing something wrong but when I try something like this

    public function columns(): array
    {
        return [
            Column::make('Actions')
                ->components([
                    Link::make('Delete')
                        ->view('livewire.includes.delete-button'),
                ]),
        ];
    }

It throws exception

 Call to a member function isHidden() on string
(View: /project/vendor/rappasoft/laravel-livewire-tables/resources/views/includes/_body.blade.php)
(View: /project/vendor/rappasoft/laravel-livewire-tables/resources/views/includes/_body.blade.php)
(View: /project/vendor/rappasoft/laravel-livewire-tables/resources/views/includes/_body.blade.php)
(View: /project/vendor/rappasoft/laravel-livewire-tables/resources/views/includes/_body.blade.php)

This seems to be because view() method in src/Views/Link.php actually returns string. However readme is referring this method as it would work like Column's view() and thus would return $this

Relationships and collections

for following snippet:

public function query() : Builder
    {
        return User::with('roles')
            ->withCount('permissions');
    }

    public function columns() : array
    {
        return [
            Column::make('ID')
                ->searchable()
                ->sortable(),
            Column::make('Name')
                ->searchable()
                ->sortable(),
            Column::make('E-mail', 'email')
                ->searchable()
                ->sortable(),
            Column::make('Role', 'roles.name')
                ->searchable()
                ->sortable(),
            Column::make('Permissions', 'permissions_count')
                ->sortable(),
            Column::make('Actions')
                ->view('backend.auth.user.includes.actions'),
        ];
    }

One user is having more than 1 roles.
How can I uses 'roles' may be lets say I want to display comma separated role names or any other kind of operations, How can I do it?

Thanks

HtmlComponents seems to be missing

Love this package. I have been using it without issue for a couple of months, but now I am trying to use format to render linkRoute output in a cell by following the instructions at https://github.com/rappasoft/laravel-livewire-tables#html-components

I get an error that HtmlComponents cannot be found. When I grep the package under vendor/rappasoft, I don't see it anywhere. Removing its inclusion then throws an error that the format function is undefined. I ran composer update to ensure I was testing against the latest version.

When I comment out format and HtmlComponents, the below code works just fine. Any help would be greatly appreciated.

	public function columns() : array
	{
		return [
			Column::make('User', 'user.full_name')->customAttribute()
				->searchable()
				->sortable(),
				/*->format(function ($model) {
					return $this->linkRoute('admin.users.edit', $model->user->full_name, $model->user_id);
				}),*/
			Column::make('Status', 'status')
				->searchable()
				->sortable()
				->view('admin.subscriptions.includes.status'),
			Column::make('Product', 'product.name_short')
				->searchable()
				->sortable(),
			Column::make('Pricing Tier', 'price.label')
				->searchable()
				->sortable()
				->view('admin.subscriptions.includes.price'),
			Column::make('Start Date', 'created_at')
				->searchable()
				->sortable()
				->view('admin.subscriptions.includes.created_at'),
			Column::make('Actions')
				->view('admin.subscriptions.includes.actions'),
		];
	}

Sorting by accessor attribute not working

Laravel version 8
Livewire Tables version 0.3.1

I have the following table:

            Column::make('id')
                ->searchable()
                ->sortable(),
            Column::make('Title')
                ->searchable()
                ->sortable(),
            Column::make('Min. Bid','MinBid')
                ->searchable()
                ->sortable(),

'id' and 'title' are normal fields and sorting works perfectly as expected, 'MinBid' is an accessor defined in the model and when I click it to sort, the table goes back to the default sorting but no actual sorting happens.

Here's the code where accessor is defined:

    public function getMinBidAttribute(){
      return Auction::where('product_id',$this->id)->min('closing_bid');
    }

Thanks for this package!

How to show relationship attribute in column

Hi,

I don't know how to show an attribute of a relationship in a column.
For example, I have a table users and each user has attribute country_id, which is a belongsTo relationship to the countries table. So if I want to show the name of the country and make that column sortable() and searchable(), what do I need to do?

Thanks

Feature Request: Add Support for Full-Page Components

I'd like to be able to be able to do this: "If the main content of a page is a Livewire component, you can pass the component directly into a Laravel route as if it were a controller."

I've worked on this myself and was able to easily add ->layout() both with and without parameters to the package. However, I got stuck when trying to implement ->slot(). I'm sure it's a simple thing that I am overlooking. I've just currently run out of time to work on it for now. I'll come back to it when I have more time if no one else figures it out first.

Maybe I'm the only one who wants this. I just thought it'd be a good feature.

Add filterable column

In addition to searching, will it be possible to define a filtering column?

More often than not there is a need to filter the table based on values in one of more columns and then search through a scoped result set.

In terms of example provided in documentation:

  • filter all users that have a role "admins"
  • search by name

does not like if you have another table component installed

Just as a comparison i have also kdion4891/laravel-livewire-tables in my test project

even if I create a new page only with your component the page will not render

Steps:

composer require rappasoft/laravel-livewire-tables
composer require kdion4891/laravel-livewire-tables
// This makes the kdion4891 component
php artisan make:table UserTable -Model=User
// This makes your component
php artisan livewire:make RUserTable

Then I have this code for your component

<?php

namespace App\Http\Livewire;

use App\User;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\TableComponent;
use Rappasoft\LaravelLivewireTables\Views\Link;

class RUserTable extends TableComponent
{
    public function query() : Builder
    {
        return User::query();
    }

    public function columns() : array
    {
        return [
            Column::make('ID')
                ->searchable()
                ->sortable(),
            Column::make('Name')
                ->searchable()
                ->sortable(),
            Column::make('E-mail', 'email')
                ->searchable()
                ->sortable(),
            Column::make('Actions')
                ->addComponent(Link::make('Edit'))
                ->addComponent(Link::make('Delete'))
        ];
    }
}

I have a /users route in my HomeController

the blade file looks like this:

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <livewire:r-user-table></livewire:r-user-table>
    </div>
</div>
@endsection

When loading the page I get the following error:

Undefined variable: header_view (View: /home/vagrant/code/test/vendor/kdion4891/laravel-livewire-tables/resources/views/table.blade.php) (View: /home/vagrant/code/test/vendor/kdion4891/laravel-livewire-tables/resources/views/table.blade.php)

I have tried

php artisan cache:clear
php artisan view:clear
composer dumpautoload

same result

I would normally not have both, but...

How to create a table using a Pivot Model?

I have the following database tables:

shops
– id
– name

products
– id
– name

product_shops
– product_id
– shop_id

How do I use the livewire to create a table based on a shop_id?

Let's say I want to view all the products in the Walmart shop!

The database would look something like this:

product_id | shop_id |
34 | 4
35 | 4
36 | 4

I now need to display in the table, the name of the product, the name of the shop and other info regarding the product!

loading events

is there a way to emit loading events on start loading and finishing something like (isLoading), to be able to use custom loading method, thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.