Laravel-datatables: rawColumns([]) doesn't work

Created on 18 Apr 2017  路  7Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

Hi @yajra,

I trying to use rawColumns but doesn't work (all columns render HTML)

When I use ->escapeColumns([]) works well, but for all the columns and I want this only for three columns. I tried with ->escapeColumns(['active', 'edit', 'name']) but doesn't work either.

Thank you for your work :))

Code snippet of problem

return Datatables::of($objects)
    ->addColumn('edit', function($object) {
        return '<a href="myroute"><button class="btn btn-sm">edit </button></a>';
    })
    ->editColumn('active', function($object) {
           if ($object->active) {
               return '<span class="label label-sm label-success">active</span>';
           }
           return '<span class="label label-sm label-danger">inactive</span>';
})
->rawColumns(['active', 'edit', 'name'])
->make();

The columns active,edit and name show the html as text, instead of render this.

I want to choose what columns will be rendered as HTML.

System details

  • yajra/laravel-datatables-oracle v7.3.0
documentation question

All 7 comments

It seems like rawColumns is being ignored when using make(false). Will try to fix this as soon as I can. Thanks for reporting.

Not a bug, since you are using make(false), you need to use the index of the column instead of name like:

->rawColumns([3,4,5])

Added on Laravel 5.4 demo for initial documentation. Thanks

Thanks @yajra :))

BTW, You know a lot about laravel... (Do not deny it!!) Do you use some package like mewebstudio/Purifier for sanitize all your inputs before save it on the database?

Regards and thanks!!

@joanebrown I just learned a lot from Laracasts. :)

Yes, I have used that package (mewebstudio/Purifier) to sanitize my input on some of my projects.

Thank you :)

Hi, there.

I'm having an issue with rawColumns. This is my scenario:

`$invoices = User::byRole('participant')->select('users.*')->findOrfail($id)->invoices()->with('city','department','store');

    return Datatables::eloquent($invoices)
    ->editColumn('created_at', function(Invoice $invoice) {
        return Date::parse($invoice->created_at)->toFormattedDateString();
    })
    ->editColumn('buyed_at', function(Invoice $invoice) {
        return Date::parse($invoice->buyed_at)->toFormattedDateString();
    })
    ->editColumn('total', function(Invoice $invoice) {
        return $invoice->totalFormatted;
    })
    ->editColumn('store.name', function(Invoice $invoice) {
        return $invoice->store->name.'<br><strong>'.$invoice->city->name.', '.$invoice->department->name.'</strong>';
    })
    ->rawColumns(['store.name','total'])
    ->make(true);`

as you can see, the field store.name which is a relationship loaded via Eager Loading works well, but on the front-end is the html is not interpreted even if I configured the field in the rawColumns. As you can see in the printscreen.
image

What am I doing wrong? Sorry if my english is not perfect.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

FilipeBorges1993 picture FilipeBorges1993  路  3Comments

Mopster picture Mopster  路  3Comments

macnux picture macnux  路  3Comments

shadoWalker89 picture shadoWalker89  路  3Comments