How do I display data from Multiple Google sheets using JSON feed URL

341 Views Asked by At

I'm able to display results and search for data from spreadsheet which has only one sheet. Using od6 as JSON URL : var url = "https://spreadsheets.google.com/feeds/list/153Obe1TdWlIPyveZoNxEw53rdrghHsiWU9l-WgGwCrE/od6/public/values?alt=json";

My requirement is to fetch JSON feed from multiple sheets like blow URL's //var url1 = "https://spreadsheets.google.com/feeds/list/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/2/public/values?alt=json"; // I tried with one URL sheet but still not able to display can you please help //var url2 = "https://spreadsheets.google.com/feeds/list/1OJX_UfZ7KQ-NMKcpXmYT8Ml1OfzerPnmUyEcSoMqeZc/3/public/values?alt=json";

<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"; // Using url1 instead of url is not working
     //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>
0

There are 0 best solutions below