Full text search

http://stackoverflow.com/questions/38429790/can-not-search-by-typing-any-part-of-the-name-from-table-using-angular-js

by Aides

HTML

<div ng-app="app" ng-controller="filtercontroller">
  <h1>Hello Plunker!</h1>
  <input class="form-control" placeholder="Type Restaurant Name" name="q" type="text" ng-model="letter">
  <table class="table table-bordered table-striped table-hover" id="dataTable">
    <thead>
      <tr>
        <th>Sl. No</th>
        <th>Restaurant Name</th>
      </tr>
    </thead>
    <tbody id="detailsstockid">

      <tr ng-repeat="cus in listOfCustomerData | startsWithLetter:letter">
        <td>{{$index+1}}</td>
        <td>{{cus.rest_name}}</td>
      </tr>
    </tbody>
  </table>
  <div class="pull-right">
    <dir-pagination-controls max-size="5" direction-links="true" boundary-links="true">
    </dir-pagination-controls>
  </div>
</div>

JavaScript

var app = angular.module('app', []);
app.controller('filtercontroller', function($scope, $http) {
  console.log('hello')
  $scope.listOfCustomerData = [{
    rest_name: 'the Joyce on 4th Irish pub',
    id: 1
  }, {
    rest_name: 'Joyce pub',
    id: 2
  }, {
    rest_name: 'The cottage',
    id: 3
  }, {
    rest_name: 'THE SHEELA BAR',
    id: 4
  }, {
    rest_name: 'Anamika pub',
    id: 5
  }]
})
app.filter('startsWithLetter', function() {
  return function(items, search) {
    //console.log('items',items);
    if (items != undefined) {
      if (!search) {
        return items;
      }
      search = search.toLowerCase();
      return items.filter(function(element) {
        return element.rest_name.toLowerCase().indexOf(search) != -1;
      });
    }
  };
});