SurfaceBulma.Table.Column (surface_bulma v0.2.0)

Defines a column for the parent table component.

The column instance is automatically added to the table's cols slot.

Properties

  • label :string, required: true - Column header text.
  • sort_by :any, default: nil - This prop takes a sort field, the following values are valid:
  • A string that is a valid field on the table
  • A function of arity 1 (uses default sorter)
  • A tuple of {sorter_function/1, compare_function/2} All three options are sent as-is to Enum.sort_by/3

If function it will be used as such:

Enum.sort_by(data, sorter_function)

Clicking the column again will simply reverse the sort, after using the same sorter function whether it is a prop sorter or function sorter.

To do compound sorts based on for example .name and .last_name, you would supply a function like this:

fn i -> {Map.get(i, :name), Map.get(i, :last_name)} end

This would sort the data by first name first, then last name.

If you need to sort things that do not compare properly with the built in <= etc, then you can supply a sorter function. For dates you would most likely want to supply the following tuple:

{fn i -> Map.get(i, :datefield) end, &Date.compare/2}

.

Link to this section Summary

Link to this section Functions

Callback implementation for Phoenix.LiveComponent.mount/1.

Callback implementation for Phoenix.LiveComponent.render/1.

Link to this function

update(assigns, socket)

Callback implementation for Phoenix.LiveComponent.update/2.