{%- set static = (static is defined ? static : false) %}
{%- set cols = (cols is defined ? cols : []) %}
{%- set rows = (rows is defined ? rows : []) -%}
{% for col in cols %}
{{ col.heading ? col.heading : ' ' }}
{% endfor %}
{% if not static %}
{% endif %}
{% for rowId, row in rows %}
{% for colId, col in cols %}
{% set cellName = name~'['~rowId~']['~colId~']' %}
{% set value = (row[colId] is defined ? row[colId] : null) %}
{% set textual = (col.type in ['singleline','multiline','number']) %}
{%- if col.type == 'select' -%}
{% include "_includes/forms/select" with {
class: 'small',
name: cellName,
options: col.options,
value: value,
disabled: static
} only %}
{%- elseif col.type == 'checkbox' -%}
{%- else -%}
{%- endif -%}
{% endfor %}
{% if not static %}
{% endif %}
{% endfor %}
{% if not static %}
{{ addRowLabel is defined ? addRowLabel : "Add a row"|t }}
{% endif %}
{% if not static and (initJs is not defined or initJs) %}
{% set js %}
new Craft.EditableTable(
"{{ id | namespaceInputId | e('js') }}",
"{{ name | namespaceInputName | e('js') }}",
{{ cols|json_encode|raw }});
{% endset %}
{% includeJs js %}
{% endif %}