laravel-table icon indicating copy to clipboard operation
laravel-table copied to clipboard

How to pass classes, when creating table through array?

Open jonasinlu opened this issue 9 years ago • 6 comments

$table = Table::create($rows, [ 'id' => '', 'name' => ['label' => trans('projects.index_label_name'), 'class' => 'test-class'], 'estimate' => trans('projects.index_label_estimate'), 'asignees' => trans('projects.index_label_asignees'), 'status' => trans('projects.index_label_status'), 'start' => trans('projects.index_label_start'), 'end' => trans('projects.index_label_end'), ]);

in this example, i'm trying to achieve the same thing as in example that you have provided with addClass() method:

$table->addColumn('status_id', trans('tasks.status'), function($model) { return $model->getStatusName(); })->addClass('fw-150 hidden-xs');

is this possible with current release or do you plan on extending this library in future to support this?

jonasinlu avatar Jan 08 '16 14:01 jonasinlu

Currently, adding classes is only supported when adding columns programmatically (i.e. using addColumn(). I'll consider it for a future release. Thanks for providing a code sample of how you'd expect such a feature to work!

gbrock avatar Jan 15 '16 10:01 gbrock

well this change would make controller action much cleaner to read the code, and actual example of this table creation with array would make more sense compared to that separate column addition.

but all in all, thank you for providing such useful code for open public, this saves so much time when trying to add fast sorting to your project. i hope, that this would become more popular in future, because i just couldn't find anything similar to this :)

thank you for your great contribution!

jonasinlu avatar Jan 15 '16 10:01 jonasinlu

Thank you for the kind words!

Considering this further, I probably wouldn't use it that way; I like keeping controllers as simple as possible, while putting every bit of HTML and HTML logic within view files. But, I also appreciate that everyone does things in their own way, and more options is never a bad thing. :thumbsup:

gbrock avatar Jan 15 '16 12:01 gbrock

well, actually the correct way (atleast from my perspective) is to place the query for data inside controller (as little as possible), and then worry about the display itself in the view files. that building of columns might be logical inside views, but i like to give structured data from controller and the view files control only the display, not what to display and what not. but you are right, everyone has their own style, and if there are more customization - it's only for the better. i hope you will keep this library alive, but i also know that such things cost time and you are not getting anything back, just kind words. but people like you are the ones who make programming such an awesome experience ;)

jonasinlu avatar Jan 15 '16 12:01 jonasinlu

Wouldn't it just work if you used the classes key in your fields array rather than class? Since setParameters() builds the method name out from the key, and there is a setClasses() method already?

drclaw avatar Apr 21 '17 20:04 drclaw

I can confirm what drclaw suggests - it works if you use classes as the key

brynj-digital avatar Sep 06 '17 10:09 brynj-digital