# `GanttEx.Live.Columns`
[🔗](https://github.com/rocket4ce/gantt_ex/blob/v0.1.0/lib/gantt_ex/live/columns.ex#L1)

Builds the grid columns from the `:column` slots of `GanttEx.Live.Gantt`.

Built-in fields get a translated label, a width, an alignment and an
inline editor by default:

| Field         | Label         | Editor      |
| ------------- | ------------- | ----------- |
| `:text`       | Task name     | `:text`     |
| `:start_date` | Start time    | `:date`     |
| `:end_date`   | End time      | `:date`     |
| `:duration`   | Duration      | `:number`   |
| `:progress`   | Progress      | `:progress` |
| `:type`       | Type          | `:type`     |
| `:wbs`        | WBS           | none        |
| `:add`        | (add button)  | none        |

Any other field is read from the task `:meta` and is not editable unless an
`editor` is given. The tree is shown in the column marked with `tree`, or
in the `:text` column.

    iex> labels = GanttEx.I18n.labels("en")
    iex> columns = GanttEx.Live.Columns.build([], labels)
    iex> Enum.map(columns, &{&1.field, &1.label, &1.tree})
    [{:text, "Task name", true}, {:start_date, "Start time", false}, {:duration, "Duration", false}, {:add, "", false}]
    iex> [owner] = GanttEx.Live.Columns.build([%{field: :owner_name}], labels, widths: %{"owner_name" => 150})
    iex> {owner.label, owner.width, owner.editor, owner.tree}
    {"Owner name", 150, nil, true}

# `t`

```elixir
@type t() :: %{
  :field =&gt; atom() | String.t(),
  :label =&gt; String.t(),
  :width =&gt; pos_integer(),
  :align =&gt; String.t(),
  :tree =&gt; boolean(),
  :editor =&gt; atom() | nil,
  :sortable =&gt; boolean(),
  :inner_block =&gt; term(),
  optional(atom()) =&gt; term()
}
```

A normalized column.

# `build`

```elixir
@spec build([map()], map(), keyword()) :: [t()]
```

Normalizes column slots (or the default columns when none are given).

## Options

  * `:widths` - widths set by the user, keyed by the field as a string.
  * `:readonly` - drops the `:add` column.

# `find`

```elixir
@spec find([t()], String.t()) :: t() | nil
```

Finds a column by its field sent as a string by the client.

# `total_width`

```elixir
@spec total_width([t()]) :: non_neg_integer()
```

Returns the sum of the column widths.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
