MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 259 forks source link

Table column labels unpredictable with dates #62

Open fergusweb opened 3 years ago

fergusweb commented 3 years ago

If I include the dates attribute, then the custom labels provided in include disappear. In below example, two columns should say "Domain Expires" and "Hosting Expires". In practice, they both say "Expires". However I remove the dates attribute, the labels will be correct. Important to note that the non-date label works in both cases, so this only seems to affect date columns.

<livewire:datatable
    model="App\Models\Domain"
    with="hosting.expiry"
    include="domain|Domain Name, expiry|Domain Expires, hosting.expiry|Hosting Expires"
    dates="expiry, hosting.expiry"
/>

This can be seen in your Intermediate example here too: https://livewire-datatables.com/intermediate You include column created_at|Created, and yet it appears in the table labelled as "Created At".

It seems to default to the mysql column name for date fields, but I'm just getting started with Laravel and couldn't figure out a fix.

dyoh777 commented 1 year ago

I ran into the same problem and I'm noting this fix if others come across it. Thanks for explaining the issue so well it saved me time. I changed the "public function formatDates($dates)" return line to this below to include the label:

return DateColumn::name($column->name)->format($format)->label($column->label);