-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add column type rendered as a badge #166
Comments
What if we want to use a badge with a Don't you think a |
Right, haven't thought about it. Maybe just a
I wouldn't add type extensions to the bundle. Instead, adding the option directly to the type would be:
However, badges can be styled in multiple ways. For example, with bootstrap, there's primary, secondary, danger, etc. Maybe it should accept a $builder->addColumn('foo', TextColumnType::class, [
'badge' => 'primary',
]); Bootstrap 5 theme would then translate that to This could be used even for the $builder->addColumn('foo', BooleanColumnType::class, [
'label' => fn (bool $value) => 'Yes' : 'No',
'badge' => fn (bool $value) => 'primary' : 'danger',
]); But using two different options may be useful in some cases, since you can overwrite one option without repeating the other. |
I totally agree with you, the idea of the extension was to use the same code everywhere for each ColumnType. Which ColumnType should have this badge option ? DateColumnType, DateTimeColumnType, EnumColumnType, LinkColumnType (?), MoneyColumnType, NumberColumnType, TextColumnType ? I fear that's a lot of duplicated code. Do I miss something ?
Yes, the same way the label is used in the forms.
Honnestly, I prefer the callback option, it's smoother |
Hello guys, you should have a look how Omines DataTables Bundle tackle this kind of stuff : # Some example columns
$table
->add('firstName', TextColumn::class, ['label' => 'customer.name', 'className' => 'bold'])
->add('lastName', TextColumn::class, ['render' => '<strong>%s</strong>', 'raw' => true])
->add('email', TextColumn::class, ['render' => function($value, $context) {
return sprintf('<a href="%s">%s</a>', $value, $value);
}])
; |
Hello, What do you mean exactly ? The |
Thanks for the suggestion @2mx. Currently, we can render anything as a badge by setting the class to the value cell: $builder->addColumn('foo', TextColumnType::class, [
'value_attr' => [
'class' => 'badge text-bg-primary',
],
]); I was just wondering whether we can simplify this... without complicating it too much by accident 😁 If you mean the |
Okay thank you, I should have read more your documentation before posting and take you time ! |
No worries! Thanks to your suggestion I've added new column type that renders the html directly for some edge cases 😁 |
By the way there is no mention to 'value_attr'' in the documentation. Would be worth it to document it :) |
True, header and value attributes are explained only in the reference section of the documentation. I've created an issue to improve that (Improve documentation about setting column header and value attributes #171). Thanks! |
Currently, we have
BooleanColumnType
that is rendered as a badge. Adding separateBadgeColumnType
to display text as a badge would be useful.For example, with Bootstrap 5: https://getbootstrap.com/docs/5.3/components/badge/#examples
There's no "badges" in HTML5, so I would render them as a text in the base theme.
The text was updated successfully, but these errors were encountered: