satya satya - 6 months ago 14
AngularJS Question

Can not search by typing any part of the name from table using Angular.js

I need one help. I can not filter data from table by typing any part of the name inside the search field using Angular.js. I am explaining my code below.

<input class="form-control" placeholder="Type Restaurant Name" name="q" type="text" ng-model="letter">
<th>Sl. No</th>
<th>Restaurant Name</th>
<tr dir-paginate="cus in ($parent.labelResults=(listOfCustomerData | startsWithLetter:letter | orderBy:'rest_name')) | itemsPerPage:5 track by $index" current-page="currentPage">
<td>{{itemsPerPage *(currentPage-1)+$index+1}}</td>

Here i am filtering the
restaurant name
by typing the name inside the input field.My controller side code is given below.

customerView.filter('startsWithLetter', function () {
return function (items, search) {
if(items != undefined){
if (!search) {
return items;
search = search.toLowerCase();
return items.filter(function(element) {
return element.rest_name.toLowerCase().substring(0, search.length).indexOf(search) != -1;

Here i need suppose i have a restaurant name
the Joyce on 4th Irish pub
.Now if i am typing each letter from the beginning of the restaurant then the its filtering from the table.but here i need suppose i am typing any part of this name like
then it should filter and display in the table.Please help me.


As stated in the comments the solution is to remove the .substring(0, search.length part since that only takes the first x (length of search word) characters of your entry and searches your search term inside that part.

Without that you search the entered word in the whole string.

See this fiddle for a working demo.