Closed ugurerkan closed 5 years ago
Do you have a specific usecase in mind for choosing this option? The way I would implement this is by giving a column a className and using css for styling or something like this
$('#table').initDataTables({{ datatable_settings(datatable) }},
{
columnDefs: [
{width: "20%", targets: 0},
]
});
Yes, CSS class could be an option but in my case, need to define and control table col widths per pages, this means a lot of classes. For example, item ID's have 20px width and action areas should fixed width instead of resize or auto calculate by DataTable.
With this way, column sizes won't change after filter, sort etc process (BTW also this is possible with autoWidth true option) and we can define exact width for columns easily/directly.
I edit a little DataTable and AbstractColumn class option maps, now I'm able to control width like below.
$dataTableFactory->create()
->add('id', NumberColumn::class, [
'width' => 20
])
->add('name', TextColumn::class, [
'width' => 100
])
->add('surname', TextColumn::class, [
'width' => 100
])
->add('email', TextColumn::class)
;
with auto calculate
with width option
I don't like exposing pure-presentation properties in the controller, or worse the table type. I understand your use case but the backend is not the place to fix it.
What is wrong with the columnDefs
suggestion above which properly keeps it in the template where it belongs?
I see now, sorry @shades684 can't catch columnDefs
part of your suggestion before.
You guys are right, keeping style rules out of bundle and controller is better approach.
BTW, thank you for this bundle @shades684 @curry684. Have a really good design and implementation, congrats.
Hello,
I think our column options must have width option like DataTables's column.width option
We can add width option to AbstractColumn class's configureOption method and then if user define a value we'll assign it to column property inside initial response's column definitions. If not, nothing will change and there won't be any BC issue.
If this is all right, I can create PR for this 🤓