// My ng-repeat is displaying the results fine, but after typing in the search box it is not filtering results as per search. please help. Also, I'm getting data from http.get // I'm new to angular js can you help how to repeat search results and display nothing when you don't enter anything in search box. // I used ng-show this is helping initially to stop showing topic and response are my column headers in sheet
<html>
<head>
<script src="menu.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script>
// Json file : https://spreadsheets.google.com/feeds/worksheets/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/public/basic?alt=json
// code for displaying the data in tabs
// Json file : https://spreadsheets.google.com/feeds/worksheets/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/public/basic?alt=json
function openPage(pageName,elmnt) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.color = "#969595";
}
document.getElementById(pageName).style.display = "block";
elmnt.style.color = "white";
}
//angular js code to display search in JSON URL data
var app= angular.module('sample', []);
app.controller('sampleController', function ($scope, $http) {
var url = "https://spreadsheets.google.com/feeds/list/153Obe1TdWlIPyveZoNxEw53rdrghHsiWU9l-WgGwCrE/od6/public/values?alt=json";
//var url1 = "https://spreadsheets.google.com/feeds/list/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/2/public/values?alt=json";
//var url2 = "https://spreadsheets.google.com/feeds/list/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/3/public/values?alt=json";
//var url = "https://spreadsheets.google.com/feeds/cells/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/1/public/values?alt=json"; // url for sheet1
$http.get(url)
.success(function(data, status, headers, config) {
$scope.users = data.feed.entry;
//console.log($scope.users);
})
.error(function(error, status, headers, config) {
console.log(status);
console.log("Error occured");
});
app.filter('highlightFilter', $sce =>
function (element, searchInput) {
element = element.replace(new RegExp(`(${searchInput})`, 'gi'),
'<span class="highlighted">$&</span>');
return $sce.trustAsHtml(element);
});
$scope.search='';
$scope.searchFilter=function(item){
if(item.gsx$topic.$t.toLowerCase().indexOf($scope.search.toLowerCase()) != -1 || item.gsx$response.$t.toLowerCase().indexOf($scope.search.toLowerCase()) != -1){
// code to highlight
// code to highlight
return true;
}
return false;
}
});
</script>
</head>
<body>
<div ng-app="sample" ng-controller="sampleController">
<input type="text" name="search" ng-model="search" placeholder="Search in all sheets" ></input>
<br>
<br>
<table style="border: 1px solid black ;" >
<tbody>
<tr>
<td style="color:blue; font-size:14px;"><center><b>Question</b></center></td>
<td style="color:blue; font-size:14px;"><center><b>Response</b></center></td>
</tr>
<tr ng-repeat="user in users | filter:searchFilter">
<td style="border: 1px solid black ; width:30%;white-space: pre-wrap;">{{user.gsx$topic.$t}}</td>
<td style="border: 1px solid black ; width:70%;white-space: pre-wrap;">{{user.gsx$response.$t}}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
If you want to add search filter on single field from $scope.users then you have to specify that property from json
<div ng-repeat="user in users | filter: { gsx$topic.$t : search}">
also please update input for modal as :
<input type="text" name="search" ng-model="search" placeholder="search" ng-click="didSelectLanguage()"></input>