2022-11-07 01:36:28 -05:00
|
|
|
<div id={@id} class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
|
2022-03-04 18:26:57 -05:00
|
|
|
<table class="min-w-full table-auto text-center bg-white">
|
|
|
|
<thead class="border-b border-primary-600">
|
|
|
|
<tr>
|
|
|
|
<%= for %{key: key, label: label} = column <- @columns do %>
|
|
|
|
<%= if column |> Map.get(:sortable, true) do %>
|
|
|
|
<th class={"p-2 #{column[:class]}"}>
|
2022-03-04 22:27:09 -05:00
|
|
|
<span
|
|
|
|
class="cursor-pointer"
|
2022-03-04 18:26:57 -05:00
|
|
|
phx-click="sort_by"
|
|
|
|
phx-value-sort-key={key}
|
2022-03-04 22:27:09 -05:00
|
|
|
phx-target={@myself}
|
|
|
|
>
|
2022-03-04 18:26:57 -05:00
|
|
|
<span class="underline"><%= label %></span>
|
|
|
|
<%= if @last_sort_key == key do %>
|
|
|
|
<%= case @sort_mode do %>
|
2022-03-04 22:27:09 -05:00
|
|
|
<% :asc -> %>
|
|
|
|
<i class="fas fa-sm fa-chevron-down"></i>
|
|
|
|
<% :desc -> %>
|
|
|
|
<i class="fas fa-sm fa-chevron-up"></i>
|
2022-03-04 18:26:57 -05:00
|
|
|
<% end %>
|
|
|
|
<% else %>
|
|
|
|
<i class="fas fa-sm fa-chevron-up opacity-0"></i>
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
</th>
|
|
|
|
<% else %>
|
|
|
|
<th class={"p-2 #{column[:class]}"}>
|
|
|
|
<%= label %>
|
|
|
|
</th>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<%= for values <- @rows do %>
|
|
|
|
<tr>
|
|
|
|
<%= for %{key: key} = value <- @columns do %>
|
|
|
|
<td class={"p-2 #{value[:class]}"}>
|
|
|
|
<%= case values |> Map.get(key) do %>
|
2022-03-04 22:27:09 -05:00
|
|
|
<% {_custom_sort_value, value} -> %>
|
|
|
|
<%= value %>
|
|
|
|
<% value -> %>
|
|
|
|
<%= value %>
|
2022-03-04 18:26:57 -05:00
|
|
|
<% end %>
|
|
|
|
</td>
|
|
|
|
<% end %>
|
|
|
|
</tr>
|
|
|
|
<% end %>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|