Search code examples
angularjsngtable

Disable ngTable sorting


I have a fairly vanilla ng-table that I provided the followings parameters for:

$scope.newRoomsTableParams = new NgTableParams(
  {
    sorting: {}
  },
  {
    total: 0,
    getData: getNewRoomsData,
    counts: []
  }
);

I want to disable the sorting feature of ng-table entirely for all columns of the table. Specifically, I want the column headers to not be clickable and to not have the up/ down arrows.

Is this possible?

Edit #1: I guess the question really comes down to interpreting the ng-table documentation which I'm not able to figure out at this moment.

Edit #2: getNewRoomsData function is empty

function getNewRoomsData() {
  return $scope.newRoomsData;
}

Solution

  • In the view (html code) remove the filter and sortable params of tag <td>.

    Example, change this:

    <table ng-table="vm.tableParams" class="table" show-filter="true">
      <tr ng-repeat="user in $data">
    
        <td title="'Name'" filter="{ name: 'text'}" sortable="'name'">
          {{user.name}}
        </td>
    
        <td title="'Age'" filter="{ age: 'number'}" sortable="'age'">
          {{user.age}}
        </td>
    
      </tr>
    </table>
    

    To this:

    <table ng-table="vm.tableParams" class="table" show-filter="true">
      <tr ng-repeat="user in $data">
    
        <!-- L@@k here below! -->
    
        <td title="'Name'">
          {{user.name}}
        </td>
    
        <td title="'Age'">
          {{user.age}}
        </td>
    
      </tr>
    </table>**