<table>
  <thead>
    <tr ng-model="$ctrl.savedSearch.api_params.select" ui-sortable="sortableColumnOptions">
      <th class="crm-search-result-select">
        <input type="checkbox" ng-checked="$ctrl.allRowsSelected" ng-click="selectAllRows()" ng-disabled="!(loading === false && !loadingAllRows && $ctrl.results[$ctrl.page] && $ctrl.results[$ctrl.page][0].id)">
      </th>
      <th ng-repeat="col in $ctrl.savedSearch.api_params.select" ng-click="setOrderBy(col, $event)" title="{{$index || !$ctrl.groupExists ? ts('Drag to reorder columns, click to sort results (shift-click to sort by multiple).') : ts('Column reserved for smart group.')}}">
        <i class="crm-i {{ getOrderBy(col) }}"></i>
        <span ng-class="{'crm-draggable': $index || !$ctrl.groupExists}">{{ $ctrl.getFieldLabel(col) }}</span>
        <span ng-switch="$index || !$ctrl.groupExists ? 'sortable' : 'locked'">
          <i ng-switch-when="locked" class="crm-i fa-lock" aria-hidden="true"></i>
          <a href ng-switch-default class="crm-hover-button" title="{{:: ts('Clear') }}" ng-click="$ctrl.clearParam('select', $index)"><i class="crm-i fa-times" aria-hidden="true"></i></a>
        </span>
      </th>
      <th class="form-inline">
        <input class="form-control crm-action-menu fa-plus" ng-model="controls.select" crm-ui-select="::{data: fieldsForSelect, placeholder: ts('Add')}" ng-change="addParam('select')">
      </th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="row in $ctrl.results[$ctrl.page]">
      <td>
        <input type="checkbox" ng-checked="isRowSelected(row)" ng-click="selectRow(row)" ng-disabled="!(loading === false && !loadingAllRows && row.id)">
      </td>
      <td ng-repeat="col in $ctrl.savedSearch.api_params.select" ng-bind-html="formatResult(row, col)"></td>
      <td></td>
    </tr>
  </tbody>
</table>
<div class="messages warning no-popup" ng-if="error">
  <h4>{{:: ts('An error occurred') }}</h4>
  <p>{{ error }}</p>
</div>
