Code Monkey home page Code Monkey logo

Comments (1)

benyaminl avatar benyaminl commented on June 14, 2024

https://yajrabox.com/docs/laravel-datatables/master/response-fractal

When using tranformer, all response manipulations must be done via transformer. Thus addColumn, editColumn, removeColumn, setRowAttr,setClassAttr, etc... should be avoided when using fractal.

https://yajrabox.com/docs/laravel-datatables/master/row-options

The methods above are extremely useful, why is fractal preventing their use?

Because with fractal it self you can return data on each row, than what's the point of adding columns with add Column or remove Column if you can change using fractal manually on the laravel transformer (TL:DR, it's redundant)?

Last time I also think I want to add Column but after learn about it's change the return as free as I want, I left addColumn if not needed.

eg :
user

  • id
  • username
  • branch
  • city
  • name
    in transformer fractal you only need to
use DataTables;
use App\User;

Route::get('user-data', function() {
    $model = User::query();

    return DataTables::eloquent($model)
                ->setTransformer(function($item){
                    return [
                        'id'                      => (int) $item->id,
                        'name'                => $item->name,
                        'branch_city'       => $item->branch . $item->city,
                    ];
                })
                ->toJson();
});

Other than like this

use DataTables;
use App\User;

Route::get('user-data', function() {
    $model = User::query();

    return DataTables::eloquent($model)
                ->setTransformer(function($item){
                    return [
                        'id'                      => (int) $item->id,
                        'name'                => $item->name,
                    ];
                })
->addColumn('branch_city', function(User $user) {
                    return $item->branch . $item->city;
                })
                ->toJson();
});

from laravel-datatables-fractal.

Related Issues (12)

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.