Git Product home page Git Product logo

laravel-livewire-tables's People

Contributors

kdion4891 avatar mikemand 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

laravel-livewire-tables's Issues

bulk delete via checkbox deletes all - not just those in view

In other places where I check-all, I expect the operation to be limited to those in view.

The action of checking all causes every model to be deleted, not just those visible on page1

I extended the warning message to indicate this, but I think the default behaviour should be to only select the models on view.

I also overrode the updatedSearch() function so that it clears previous checkbox selection when making a new search so that items not in view are not accidentally deleted.

    public function updatedSearch()
    {
        $this->gotoPage(1);
        $this->checkbox_all = false;
        $this->checkbox_values=[];
    }

Searchable not working

Laravel Framework 7.7.1,
Laravel-livewire-tables: 1.6


class InsiderFilingTable extends TableComponent
{
    public $table_class = 'table-hover';
    public $thead_class = 'thead-light';
    public $checkbox = false;
    public $per_page = 20;
    public $searchable = true;
    public $sort_attribute = 'col1';

   public function query()
    {
        return InsiderFiling::query();
    }

    public function columns()
    {
        return [
            Column::make('PS', 'col1')->searchable()->sortable(),
            Column::make('Ticker', 'col2')->searchable()->sortable(),
            Column::make('Insider', 'col3')->searchable()->sortable(),
            Column::make('Comp', 'col4')->searchable()->sortable(),
     
        ];
    }
}

No error, searchable is not working.
Here is website url.

http://insiderfollower.tk/insider-trading-filing

Thank you

Suggestion to add tdPresenter()

I was getting frustrated by wanting columns formatted in a particular way, adding an accessor to the model, adding the accessor to the $appends of the model, then putting the accessor name in the Column:make()

Then after doing all this, invariably, the search and sort functions would be broken because livewire tables tries to use the accessor in the model search and sort by, resulting in unknown column (name of accessor)

The below seems to be a simple way to deal with this, and in keeping with the package;

Having published the views; In the laravel-livewire-tables/table.blade.php;

change

    {{$value}}

to

     {{ $this->tdPresenter($column->attribute, $value) }}

each cell will now call the tdPresenter function in the component, passing the column name and the value

In the component, add a method, like;

    public function tdPresenter($attribute, $value)
    {
        if ($attribute == 'budget') return '£' .  round($value, 2);
        if ($attribute == 'created_at') return Carbon::parse($value)->format('H:i D d.m.y');
        if ($attribute == 'updated_at') return Carbon::parse($value)->format('H:i D d.m.y');

        return $value;
    }

Now I can format dates and currencies in the component, I don't have to pollute my models, and sorting and searching still works on these columns.

CONCAT two columns ?

Hi, awesome package. I love it. If is possible I would like to sponsor it.

Anyways, is there a way to CONCAT two db columns like FirstName and LastName ?

Column::make('First Name', 'FirstName')->searchable()->sortable(),
Column::make('Last Name', 'LastName')->searchable()->sortable(),

Call to undefined method when using relationship with camel case

Hi, i have an issue when searching using camel case relation name

this is my error

Call to undefined method App\Invoice::student_study()

this is my code

<?php

namespace App\Http\Livewire;

use App\Invoice;
use Kdion4891\LaravelLivewireTables\Column;
use Kdion4891\LaravelLivewireTables\TableComponent;
use Illuminate\Support\Facades\DB;

class InvoiceReportTable extends TableComponent
{
    public $checkbox = false;
    public function query()
    {
        $q = Invoice::with(['payments', 'studentStudy.student', 'branch', 'studentStudy.study'])
            ->withCount([
                'payments AS paid_sum' => function ($query) {
                    $query->select(DB::raw("SUM(amount) as paid_sum"));
                }
            ]);

        return $q;
    }

    public function columns()
    {
        return [
            Column::make('Cabang','branch.name')->searchable()->sortable(),
            Column::make('Nomor Transaksi','code')->searchable()->sortable(),
            Column::make('Nama Siswa','student_study.student.name')->searchable()->sortable(),
            Column::make('Studi','student_study.study.name'),
            Column::make('Jumlah Tagihan','amount')->sortable()->view('reports.invoice.amount'),
            Column::make('Jumlah Dibayar','paid_sum')->view('reports.invoice.paid_sum'),
            Column::make('Status','status')->view('reports.invoice.status'),
        ];
    }
}

Is there any way to add selectbox to change perpage?

Hello,

This livewire table is really awesome.
If I am not wrong, you didn't add per page selection somewhere?
Is it hard to add that?
I know we can set public $per_page=x; for per page, but is it hard to add select box on front like other datatable?
Thanks

Returning Relationships from `query()` method

Something I want to note for anyone else that may stumble upon this issue: If you return a relationship from the query() method (example below) make sure you call ->getQuery() at the very end to transform the return type from one of the relationships (abstract class: \Illuminate\Database\Eloquent\Relations\Relation) to an Eloquent Builder. The exception thrown is as follows:

Symfony\Component\Debug\Exception\FatalThrowableError Argument 1 passed to Kdion4891\LaravelLivewireTables\TableComponent::attribute() must be an instance of Illuminate\Database\Eloquent\Builder, instance of Illuminate\Database\Eloquent\Relations\HasMany given

An example of a bad query:

public function query()
{
	return $this->building->expenses()->where('type', 'monthly');
}

And now for a good:

public function query()
{
	return $this->building->expenses()->where('type', 'monthly')->getQuery();
}

Edit: I should note this only causes a problem when searching or sorting. Pagination might be fine, I didn't test that.

Defer loading option

Hey,

Loving the package so far! Have you considered adding a deferred loading to the package? I cannot see any negatives to doing this even by default... but you could also provide a config for it.

I have implemented it by extending your table component as follows (the below method ensures pagination is not broken during loading)

class TableComponent extends BaseTableComponent
{
    public $loaded = false;

    public function tableLoaded()
    {
        $this->loaded = true;
    }

    public function tableView()
    {
        return view('laravel-livewire-tables::table', [
            'columns' => $this->columns(),
            'models' => $this->loaded ?
                $this->models()->paginate($this->per_page)
                : $this->emptyModel(),
        ]);
    }

    private function emptyModel()
    {
        return $this->query()->paginate();
    }
}

Then at the top of the table livewire component

<div wire:init="tableLoaded"></div>

What do you think?

->hidden() column attribute

One feature that would push a great package "over the top" in my opinion would be the addition of hidden() as a column attribute similar to sortable() and searchable().

For example, Column::make('ID')->searchable()->sortable()->hidden(). This would allow for a column listing to be shown to the user and let them determine what columns are important to see.

Thoughts?

Remove Inline Styles and add tr, th, td public properties

Hi,

This is an excellent table replacement for dataTables, however adding inline styles is not great, for example the click span has same inline style just to add a cursor when this can be done via CSS.

For consistency across this package it would be good to have:-
Public property class defaults for tbody, tr, th, td elements whereas table and thead have.

Expected simple table so styles can be added at the CSS level rather than have to remove them and/or then add in needed styles.

Thanks

Kev

[Question] Date casting (and other castings)

I noticed between Laravel 6 and Laravel 7 the way which date castings are handled in this package. On L6 we got a pretty date format, while on L7 we get something like 2020-03-14T00:16:13.000000Z.

I assume this is the way in which Laravel is handling the casting.

Question: is it possible to manipulate the data being outputted to the table without creating a new view file. i.e. something inline?

How can I use search on secondary table in joining statement?

public function query()
{
$response = Transaction::latest()->select('transactions.*', 'users.name', 'users.mobile')
->join('users', 'transactions.user_id', 'users.id');
return $response;
}

public function columns()
{
return [
// Column::make('ID')->searchable()->sortable(),
Column::make("Date", 'created_at')->view('livewire.admin.partial.common.date-format')->sortable(),
Column::make('Order No', 'order_id')->searchable()->sortable(),
Column::make('Name', 'name')->searchable('users.name')->sortable(),
Column::make('Amount')->sortable(),
Column::make("Payment", 'payment_status')->view('livewire.admin.partial.common.payment-status'),
Column::make("Service", 'order_status')->view('livewire.admin.partial.common.service-status'),
Column::make()->view('livewire.admin.partial.common.common-action'),
];
}

Transform column data from model

Hi @kdion4891

Very nice project you have created here! I was wondering, is it possible to transform the data before serving it to the table?

For example, if I have a name column, I would like to make sure that the first character is always capitalized:

public function columns()
    {
        return [
            Column::make('Name', 'first_name')->searchable()->sortable(),
        ];
    }

How can I do so I can use ucfirst('first_name') for example?

Error when creating table

when i try to create table with comman:
php artisan make:table UserTable --model=User

if got an error.
step that i took:
i clone https://github.com/calebporzio/laracasts-livewire-datatable.git
it had working Livewire on Laravel 6.2

system that i have:

Apache 2.43
PHP 7.4.4
SQLITE

error that i've got:

D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master
λ php artisan make:table UserTable --model=App\User -v

   BadMethodCallException  : Method Illuminate\Filesystem\Filesystem::ensureDirectoryExists does not exist.

  at D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php:103
     99|      */
    100|     public function __call($method, $parameters)
    101|     {
    102|         if (! static::hasMacro($method)) {
  > 103|             throw new BadMethodCallException(sprintf(
    104|                 'Method %s::%s does not exist.', static::class, $method
    105|             ));
    106|         }
    107|

  Exception trace:

  1   Illuminate\Filesystem\Filesystem::__call("ensureDirectoryExists")
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:245

  2   Illuminate\Support\Facades\Facade::__callStatic("ensureDirectoryExists")
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\kdion4891\laravel-livewire-tables\src\Commands\MakeTable.php:20

  3   Kdion4891\LaravelLivewireTables\Commands\MakeTable::handle()
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  4   call_user_func_array([])
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  5   Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Container\Util.php:34

  6   Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:90

  7   Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:34

  8   Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), [])
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Container\Container.php:590

  9   Illuminate\Container\Container::call()
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Console\Command.php:202

  10  Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\symfony\console\Command\Command.php:255

  11  Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Console\Command.php:189

  12  Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\symfony\console\Application.php:934

  13  Symfony\Component\Console\Application::doRunCommand(Object(Kdion4891\LaravelLivewireTables\Commands\MakeTable), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\symfony\console\Application.php:273

  14  Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\symfony\console\Application.php:149

  15  Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Console\Application.php:90

  16  Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:131

  17  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      D:\MyDocuments\webdev\laravel\laracasts-livewire-datatable-master\artisan:37


what do i wrong?
thx

Make row clickable

This is an amazing package, it's very handy - one thing I feel would be a great advantage would be to be able to make the row clickable to go to the relevant record.

Is this something potentially in the pipeline, or is there a workaround?

add export option

hello, thank you for great package I think it would be good idea to add export option for tables.

Add export to .pdf as well

Is it possible to add as a feature the ability to export as pdf also based on the file extension and customizable filenames.

Example for restricting the results

It has taken me more time than it should... I only wanted users with the role_id = 1

I now have a solution and I wanted to share it.

class UserTable extends TableComponent
{
public $role_id;
public function query()
{
if ($this->role_id!= null)
return User::where('role_id',$this->role_id);
return User::query();
}
public function mount($role_id= null)
{
$this->setTableProperties();
if ($role_id!= null)
$this->role_id= $role_id;
}
public function columns()
{
return [
Column::make('ID')->searchable()->sortable(),
Column::make('url')->searchable()->sortable(),
Column::make('status')->searchable()->sortable(),
Column::make('type')->searchable()->sortable(),
Column::make('role')->searchable()->sortable(),
Column::make('processed_at')->searchable()->sortable(),
Column::make('Created At')->searchable()->sortable(),
Column::make('Updated At')->searchable()->sortable(),
];
}
}

and in the view:

@livewire('user-table',['role_id'=>$role->id])

I hope I could help

Don't works if model primaryKey is not `id`

I've a model, Customer

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    protected $table = 'customer';
    protected $primaryKey = 'id_customer';
}

and i've this error:
Capture d’écran 2020-09-01 à 19 52 15
If i change to key (in the database) to id it's working !

I'm issing something ?

Thanks

multiple sort fields

How is it possible to sort by default by 2 fields?
e.g. last_name, first_name

Default sort

Is there a way to add a default sort to the view? I can't add it to the query as then it overrides the ability to sort by the other columns later.

How to capture selected value from outside component?

I am able to create the datatable easily and then my issue is when i select multiple rows through checkbox, i dont know how to create a button (e.g. an Activate button) that can take capture the value of selected rows

Slow check box select

I am not sure if you agree, but I feel like the speed of the check box-checking is quite slow, even with a small number of models in the table.

Do you have any hunches as to what may be causing this? Quite a while ago I implemented my own attempt. I actually never pushed the code and I think it is on my old laptop so would have to go digging for it, but this was the result.

Kapture 2019-12-01 at 20 05 06

Just to be clear, your package is superior in every way. I just wonder if we can make this particular element a little faster.

Not sure if you have looked into it or have any ideas? I would be happy to have a look into it also.

Sortable columns with JSON path

Hi Kevin,

I'm wondering if you would find it useful to be able to do sorting on a column's JSON path? For example, with Laravel I can sort using the following:

$models->orderBy('total->amount');

Where the total column is JSON with a Money object ({"amount": 23500, "currency": "USD"}) stored.

I have an implementation already working on my fork if you want to see: mikemand/laravel-livewire-tables@8d9ccb3

My only problem, however, is how MySQL (I don't know about other RDBMSes) sorts numeric values. It is very literal, so 11 comes before 2 (e.g.: 1, 11, 3, 5, 7, 9). I could solve this by checking if the $sort_attribute contains -> and then using:

$models->orderByRaw("cast({$sort_attribute}->'$.{$jsonPath}' as unsigned) {$this->sort_direction}")

instead of the typical orderBy, but I don't know if you want this kind of complexity in your package? What are your thoughts?

optional pagination

Is there a need for optional pagination? I have serveral Tables on one page and pagination would intnerfere with all other tables - even thoug they do not have enough entries to actually use pagination. As a result, they would show 'No results to display'.
In my fork I made pagination optional using 'public $pagination = false;' and changes in table.blade.php and TableComponent.php.
It would be great, if pagination would work on indepandet tables on the same page! Bit i do not know how to do that. :-(

Individual Column Search

Is there a way to search individual columns instead of searching trough all the columns?
see screenshot below

image

Passing another variable on Cloumn use view

`

return [

    Column::make('ID')->searchable()->sortable(),
    Column::make('Brand Name', 'brand.name')->searchable()->sortable(),
    Column::make('Name')->searchable()->sortable(),
    Column::make('Color')->searchable()->sortable()->view('cars.table-color'),
    Column::make('Accidents', 'accidents_count')->sortable(),
    Column::make()->view('cars.table-actions'),
];

`

i need passing another variable on ->view('cars.table-color')

->view('cars.table-color', ['var' => 1]) ===> not working

Foreign json column

Hello,
Great work you put into the package, really simple and useful.
I have a quick question,
Is there a way of how we can create a column out of json column in a foreign table and make it sortable and searchable?

Thanks

artisan make broken for namespaced classes

For example php artisan make:table BarTable --model=Models\Foo\Bar creates a class with the following query() method

    public function query()
    {
        return ModelsFooBar::query();
    }

This is pretty easy to fix, but noting it anyway.

CONCAT two values in a column

Hey I aready try to concat two values using an Accessor but I+m always getting this error, Column not found: 1054 Unknown column 'users.full_name' in 'field list'

How to pass variable?

I want to pass variable to livewire component.
@livewire('livewire-component', ['type'=>'A'])
public function mount($type) { $this->setTableProperties(); $this->type = $type; }
It displayed error.
Declaration of App\Http\Livewire\LivewireComponent::mount($type) should be compatible with Kdion4891\LaravelLivewireTables\TableComponent::mount() (View: ~\resources\views\app\tabl.blade.php)

Thanks

mount method overide

When overriding the mount method and passing a variable to it.
e.g.

//view
@livewire('test-table', ['search' => $search])
//Component
public function mount($search)
    {
        $this->setTableProperties();
        $this->search = $search;
    }

This error shows up.
Declaration of App\Http\Livewire\TestTable::mount($search) should be compatible with Kdion4891\LaravelLivewireTables\TableComponent::mount() (View: F:\PHP Projects\diagnoMarch19\resources\views\result.blade.php)

Sorting relationships on table

Hello,

Thank you for this package.

I do have some issues though.

I have these tables: coffees, roast_types, green_beans.

In the Coffee model I have these relationships:

public function roast_type()
    {
        return $this->belongsTo(RoastType::class);
    }

     public function green_bean()
    {
        return $this->belongsTo(GreenBean::class);
    }

In the CoffeeTable component I have this query:

return Coffee::with('roast_type')
        ->with('green_bean')
            ->where('coffees.active', $this->active)
            ->where('blend', 0);

and these columns:

return [
            Column::make('ID')->searchable()->sortable(),
            Column::make('Name')->searchable()->sortable(),
            Column::make('Green Bean', 'green_bean.name')->searchable()->sortable(),
            Column::make('Roast Type', 'roast_type.name')->searchable()->sortable(),
            Column::make()->view('admin.coffee.table_actions'),
        ];

I have 2 problems:

  1. When I click on sorting the Roast Type column the values in the Name column change to the Roast type name instead of the Coffee name.

  2. When I click on sorting the Green Bean column, I get this error:

Missing required parameter for [Route: coffees.edit] [URI: coffees/{coffee}/edit] [Missing parameter: coffee]. (View: C:\wamp64\www\highland8.local\resources\views\admin\coffee\table_actions.blade.php)

What am I doing wrong?

BTW, I added some functionality like in the jquery dropdown tables, to show:

  1. A dropdown for the user to select how many records to display on the page
  2. A paragraph that shows how many records are displayed from the total results

Can you please help with my issues?

Livewire 2

Is it possible to add support for Livewire 2.*?

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.