<div class="row">
  <div class="panel panel-default">
    <div class="panel-heading">

    <!-- Database Table -->

      <div class="row">
        <div class="col-xs-6">
          <b>
          Displaying rows {{ s.row1 }}-{{ s.row2 }} out of {{ s.nrows }}
          </b>
          {% if s.query %}
          <a href="/{{ p.name }}/?query={{ s.query }}"> (direct link) </a>
          {% endif %}
        </div>

        <div class="col-xs-6">
          <div class="btn-group pull-right">
            <button type="button"
                    class="btn btn-default dropdown-toggle btn-sm"
                    data-toggle="dropdown" aria-haspopup="true"
                    aria-expanded="false">
            Add Column <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
            {% for key, value in p.key_descriptions|dictsort(false, "value") if key in t.addcolumns %}
              <li><a href="javascript:update_table({{ s.id }},
                                                   'toggle',
                                                   '{{ key }}')">
              {{ value[1] }} ({{key}}) </a></li>
            {% endfor %}
            </ul>
          </div>

          <div class="btn-group pull-right">
            <button type="button"
                    class="btn btn-default dropdown-toggle btn-sm"
                    data-toggle="dropdown" aria-haspopup="true"
                    aria-expanded="false">
            Rows: {{ s.limit }} <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
            {% for n in [10, 25, 50, 100, 200] %}
              <li><a href="javascript:update_table({{ s.id }},
                                                   'limit',
                                                   {{ n }})">{{ n }}</a></li>
            {% endfor %}
            </ul>
          </div>
        </div>
      </div>
    </div>

    <div class="panel-body">
    </div>

    <!-- Table -->
    <table id="rows" class="table table-striped">

    <tr>
    {%- for c in t.columns %}
      <th class="text-center">

      {% set desc, longdesc, unit = p.key_descriptions[c] %}
      {% set unit = unit and ' [' + unit + ']' %}

      {% if s.sort == c %}&#x2193;
      {% elif s.sort == '-' + c %}&#x2191;
      {% endif -%}

      {% if c == 'formula' %}
        <span data-toggle="tooltip" title="key: formul">Formula</span>
      {% else %}
        <a href="javascript:update_table({{ s.id }}, 'sort', '{{ c }}')"
           data-toggle="tooltip" title="key: {{c}}{{unit}}">{{ desc }}</a>
      {% endif %}
      <a href="javascript:update_table({{ s.id }}, 'toggle', '{{ c }}')"
         data-toggle="tooltip" title="Remove column">&#x2715;</a>
      </th>
    {%- endfor %}
    </tr>

    {% for row in t.rows -%}

      <tr id="rowentry" class="rowentry">
      {%- autoescape false -%}
      {%- for s in row.strings -%}
        <td class="text-center">
        <a href="/{{ p.name }}/row/{{ row.uid }}">
        {%- if s != "" -%}{{ s }}{% else %}-{% endif %}
        </a>
        </td>
      {% endfor %}
      {% endautoescape %}
      </tr>
    {% endfor %}
    </table>
  </div>
</div>


<div class="text-center">
  <nav aria-label="Page navigation">
  <ul class="pagination pagination-sm">

  {% for page, name in s.paginate() %}
    {% set hrefstr="#" %}
    {% if page >= 0 %}
      {% set hrefstr = 'javascript:update_table(' + s.id|string +
                                                ", 'page', " +
                                                page|string + ')' %}
    {% endif %}
    {% if name=="previous" %}
      <li>
      <a href="{{hrefstr}}" aria-label="Previous">
      <span aria-hidden="true">&laquo;</span>
      </a>
      </li>
    {% elif name=="next" %}
      <li>
      <a href="{{hrefstr}}" aria-label="Next">
      <span aria-hidden="true">&raquo;</span>
      </a>
      </li>
    {% elif name=="..." %}
      <li class="inactive"><a href="{{hrefstr}}">{{ name }}</a></li>
    {% elif page < 0 %}
      <li class="active"><a href="{{hrefstr}}">{{ name }}</a></li>
    {% else %}
      <li><a href="{{hrefstr}}">{{ name }}</a></li>
    {% endif %}
  {% endfor %}

  </ul>
  </nav>
</div>
