Wednesday 15 January 2014

javascript - how to search for a fixed value when clicked on search button from a list which is already retrieved from database using AngularJs -



javascript - how to search for a fixed value when clicked on search button from a list which is already retrieved from database using AngularJs -

i using search functionality searched records list retrieved database , populated in html page,i getting filtered search not finish search list in controller. need fixed value result showed when clicked on search button(eg.i should not 'john' when searched 'j',i should exact value search),can 1 help me out. this piece of html code.

<ul class="col-sm-11 col-xs-12 searchfields"> <li class="col-md-2 col-sm-4"><span class="col-xs-12">tin</span><input type="text" ng-model="data.providertin" ng-keyup="formattin($event)" ng-trim="false" ng-blur="clearerror()" id="tinelem" placeholder="tin" maxlength="11" autofocus /></li> <li class="col-md-2 col-sm-4"><span class="col-xs-12">last name</span><input type="text" ng-model="data.providerfulllastname" ng-keyup="formatlast($event)" placeholder="last name" maxlength="20" /></li> <li class="col-md-2 col-sm-4"><span class="col-xs-12">first name</span><input type="text" ng-model="data.providerfirstname" ng-keyup="formatfirst($event)" placeholder="first name" maxlength="12" /></li> <li class="col-md-2 col-sm-4"><span class="col-xs-12">city</span><input type="text" ng-model="data.prvdadrcitynm" ng-keyup="formatcity($event)" placeholder="city" maxlength="21" /></li> <li class="col-md-2 col-sm-4"><span class="col-xs-12">state</span><input type="text" ng-model="data.prvdadrstcd" ng-keyup="formatstate($event)" ng-trim="false" ng-blur="clearerror()" placeholder="state" maxlength=2 /></li> <li class="col-md-2 col-sm-4"><span class="col-xs-12">phone</span><input type="text" ng-model="provider.prvdtelnum" ng-keyup="formatphone($event)" ng-blur="clearerror()" placeholder="(xxx) xxx-xxxx" onkeydown="javascript:backspacerdown(this,event);" onkeyup="javascript:backspacerup(this,event);" maxlength="14" required /></li> </ul> <div class="col-md-1 col-sm-4 searchblock"> <button class="searchbtn" type="button" id="searchbtn" ng-click="">search</button> </div> <tr ng-repeat= "data in recommendatnlist| filter:searchd" > <td><a href="#/viewprvddtlpage/{{data.providerid}}" class="openlink">{{data.providertin}}</a></td> <td>{{data.providerfulllastname}}</td> <td>{{data.providerfirstname}}</td> <td>{{data.providerpracticename}}</td> <td>{{data.prvdadrcitynm}}</td> <td>{{data.prvdadrstcd}}</td> <td>{{data.prvdadrxpndzipcd}}</td> <td>{{data.measure}}</td> <td>{{data.grade}}</td> <td>{{data.measurepaid}}</td> <td>{{data.totalpaid}}</td> <td>{{data.nooflettrsanymeasure}}</td> <td>{{data.nooflettrsrecommmeasure}}</td> <td>{{data.currclaimanymeasure}}</td> <td>{{data.currclaimcurrrecomm}}</td> <td class="interventtblecol"><input type="checkbox" ng-checked="data.letter" ng-model="data.letter"></td> <td class="interventtblecol"><input type="checkbox" ng-checked="data.mcr" ng-model="data.mcr"></td> <td class="interventtblecol"><input type="checkbox" ng-checked="data.fcr" ng-model="data.fcr"></td> <td class="interventtblecol"><input type="checkbox" ng-checked="data.siu" ng-model="data.siu"></td> <td class="interventtblecol"><input type="checkbox" ng-checked="data.removeclaimrvw" ng-model="data.removeclaimrvw" ></td> <td class="interventtblecol"><input type="checkbox" ng-checked="data.flag" ng-model="data.flag"></td> </tr>

and controller

angular.module('admapp').controller( "recommendationctrl", [ '$scope', '$stateparams', 'recommendationservice', function($scope, $stateparams, recommendationservice) { recommendationservice.fetchrecommendatns().then(function(data) { alert("data"+json.stringify(data)); $scope.recommendatnlist=data; });

that odd thing request.

tl;dr: plunkr illustration on explicit filter wrote below, bit more beginners struggling angularjs.

but trying create explicit filter?

like if have

$scope.records = [{name:'john', phone:'555-1276'}, {name:'mary', phone:'800-big-mary'}, {name:'mike', phone:'555-4321'}, {name:'adam', phone:'555-5678'}, {name:'julie', phone:'555-8765'}, {name:'juliette', phone:'555-5678'}];

you want j nowadays nil , john nowadays name:john, phone: 555-1276 ?

if case need utilize anuglarjs custom filters.

i've created plunker reason: working explicit filter using same records above.

the filter method rather not smart i'll give short explanation :

newapp.filter('explicitsearch',function(){ //angularjs -> declaring new filter in our newapp module. homecoming function(items, string){ //the parameters here: first parameter in filter homecoming function info referring to. //the sec parameter argument passing filter, //example : looks <tr ng-repeat='friend in friends | filtername:filtersecondparam'> var filtered = []; //this array, going our filtered results. //this simple js code, iterate on info filter have passed, if find explicitly equal, add together our filtered array. (var = 0; < items.length; i++) { var item = items[i]; if (item.name === string) { filtered.push(item); } if(item.phone === string){ filtered.push(item); } } homecoming filtered; } });

use upon html:

<body ng-controller='ctrl'> search: <input ng-model="searchtext"> <table> <thead> <tr> <th>name</th> <th>phone</th> </tr> </thead> <tbody> <tr ng-repeat='record in records | explicitsearch:searchtext '> <td>{{record.name}}</td> <td>{{record.phone}}></td> </tr> </tbody> </table> </body>

javascript html angularjs

No comments:

Post a Comment