I have a search functionality from my table as per the Restaurant Name using angular.js. Suppose there are many 'Restaurant Names' and if user is typing the first letter of any name its not filtering as per required after typing 2/3 letter its filtering properly.
Here is my code:
<div class="input-group" style="margin-bottom:10px; width:300px;">
<input class="form-control" placeholder="Type Restaurant Name" name="q" type="text" ng-model="searchProduct.rest_name">
</div>
<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 dir-paginate="cus in ($parent.labelResults=(listOfCustomerData | filter:searchProduct.rest_name:startsWith | orderBy:'rest_name')) | itemsPerPage:5 track by $index" current-page="currentPage">
<td>{{itemsPerPage *(currentPage-1)+$index+1}}</td>
<td>{{cus.rest_name}}</td>
</tr>
</tbody>
</table>
Controller side code is here:
$scope.startsWith = function (actual, expected) {
//console.log('hello',actual);
var lowerStr = (actual + "").toLowerCase();
return lowerStr.indexOf(expected.toLowerCase()) === 0;
}
I have many restaurant name such as Anjum,A&P Chinese Food Express,Bookers BBQ & Crab Shack,Butcher And The Baker, Cactus Club Stephen Avenue,Cactus Club - Macleod Trail.
When user is typing only a inside the search box the names started with a should filter but its not happening like that. All data is showing after type 2/3 letter the filtration process is working. Here I need when user will type the first letter, the names related to that search letter will filter.