Align cells left after 2.0
Align cells left after 2.0
From the release notes of 2.0:
Auto type detection class assignment. Class names are applied automatically to the table columns based on the detected column type. We now automatically right align number and date columns.
I have date type cells, that now automatically gets the dt-type-date
class assigned. This class will right align columns.
To custom align columns, you are seemingly supposed to add the dt[-head|-body]-left
class: https://datatables.net/manual/styling/classes
The problem is, the custom class is added before the automatic class, so its styles are overwritten, including the for me important text-align
.
How can i left align a date cell in datatables 2.0? I don't want to change the type of the cell, because that would break ordering.
Answers
Hi,
You can control the class names that are automatically assigned to a type through the new
DataTable.type()
method (some discussion on the built in types here).For example:
Interestingly it ignores the setting if you pass an empty string - that's an error I'll correct.
You could assign other classes if you prefer. It looks like
dt-type-date
will take preference overdt-left
regardless of order in the class list, I suspect due to the ordering in the CSS. I'll look at that as well.Thanks for flagging this up.
Allan
A related problem is that dt-type-date alignment also right-aligns the th cell causing it to overlap with the sorting arrows (at least on Bootstrap 5).
I'm not seeing that here or here.
Are you able to give me a link to a page that is showing the issue please? It sounds like the padding that the DataTables / Bootstrap integration stylesheet is applying to the header for exactly that reason isn't on the table you are looking at for whatever reason.
Allan
I figured out where the problem is happening. My table uses table-sm to reduce the padding in the cells. If you add the table-sm class to the live.datatables.net link above it reproduces the problem I am seeing.
Brilliant! Thanks for letting me know about that. I've committed a fix which will be in DataTables 2.0.1.
Regards,
Allan
I appreciate it. Thank you!