SurfaceBulma.Table.Column (surface_bulma v0.5.1)

Defines a column for the parent table component.

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

properties

Properties

  • label :string, required: true - Column header text
  • show :boolean, default: true
  • 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, or a list of selectors to access nested data. If element of list is binary or atom, Map.get is used, if it is an integer, Enum.at is used.
  • A function of arity 1 (uses default sorter)
  • A tuple of {sorter_function/1, compare_function/2}
  • A tuple of {list_of_selectors, compare_function/2}. The list of selectors is the same as described above. 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

Link to this function

render(assigns)

Callback implementation for Surface.Component.render/1.