defmodule LiveAntd.Components.Table do @moduledoc """ A table for normal way (it's not antd style.) ## API * [x] `title`: table title * [x] `withCard`: with card compoenent. * [x] `data`: Data record array to be displayed * [x] `rowClass: Row's className function(record, index) * [x] `paginate: Table with data pagination * [x] `onChange`: Callback executed when pagination, filters or sorter is changed ## Example {{ item.event_id }} {{ item.event_name }} {{ item.event_position }} {{ item.event_id }}
""" use Surface.Component alias LiveAntd.Components.Card alias LiveAntd.Components.Empty alias LiveAntd.Components.Pagination import LiveAntd.Helper # event prop(onChange, :event) # api property prop(data, :list, required: true) prop(title, :string) prop(withCard, :boolean, default: true) prop(rowClass, :fun) prop(class, :css_class) prop(paginate, :map, default: %{total_pages: 0, current_page: 0, per_page: 10, total_count: 0}) # slot @doc "The columns of the table" slot(cols, props: [item: ^data], required: true) def render(assigns) do # 如果列表为空,则返回 empty case length(assigns.data) do 0 -> render_empty(assigns) _ -> render_table(assigns) end end def render_table(assigns) do case assigns.withCard do true -> ~H""" {{ render_basic_table(assigns) }} """ false -> render_basic_table(assigns) end end def render_basic_table(assigns) do ~H"""
{{ col.label }}
""" end defp row_class_fun(nil), do: fn _, _ -> "" end defp row_class_fun(rowClass), do: rowClass end