Aim

Using Rest API With AngularJS, get SharePoint List Items and customization of search with Text, Lookup, and Person/Group type Fields.

Step 1

In my example, I have created two Lists. They are,

  • Product Sales
  • Phone

Step 2

In Phone Custom list, I created Title,Priority, and Demo single line text data type columns. And in second List i.e Produc Sales, I have created Product,Total_x0020_Sales,Sales_x0020_Target,SalesPerson,LPhone and SalesName.

  • Here,"LPhone" is Lookup Field link with our Phone Custom list field of Title.
  • "SalesName" is person/Group filed type and Show Field is FirstName.

Step 3

Create .js file file,

  1. var spApp = angular
  2. .module("spApp", [])
  3. .controller("viewItemController", function ($scope, $http) {
  4. var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Product%20Sales')/items?$select=Product,Total_x0020_Sales,Sales_x0020_Target,SalesPerson,SalesName/FirstName,LPhone/Title&$expand=LPhone,SalesName";
  5. $http(
  6. {
  7. method: "GET",
  8. url: url,
  9. headers: { "accept": "application/json;odata=verbose" }
  10. }
  11. ).success(function (data, status, headers, config) {
  12. var dataResults=data.d.results;
  13. var item = data.d.results[1];
  14. $scope.contacts = dataResults;
  15. $scope.productItems = function(item)
  16. {
  17. if($scope.searchText==undefined)
  18. {
  19. return true;
  20. }
  21. else{
  22. if((item.SalesPerson.toLowerCase().indexOf($scope.searchText.toLowerCase())!=-1)||(item.Product.toLowerCase().indexOf($scope.searchText.toLowerCase())!=-1))
  23. {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. }).error(function (data, status, headers, config) {
  30. });
  31. })
Step 5

Create .html File,
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/SiteAssets/angular.min.js"></script>
  4. <script type="text/javascript" src="/SiteAssets/angularGet.js"></script>
  5. </head>
  6. <body>
  7. <h3>View Contacts</h3>
  8. <hr/>
  9. <div ng-app="spApp">
  10. <div ng-controller="viewItemController"> <input type="text" placeholder="Product&SalesPerson" ng-model="searchText" /> <br/><br/>
  11. <table>
  12. <tr>
  13. <th>Product</th>
  14. <th>Total Sales</th>
  15. <th>Sales Target</th>
  16. <th>Sales Peron</th>
  17. <th>LookUPFieldData</th>
  18. <th>Person/GroupField</th>
  19. </tr>
  20. <tr ng-repeat="contact in contacts|filter:productItems">
  21. <td>{{contact.Product}}</td>
  22. <td>{{contact.Total_x0020_Sales}}</td>
  23. <td>{{contact.Sales_x0020_Target}}</td>
  24. <td>{{contact.SalesPerson}}</td>
  25. <td>{{contact.LPhone.Title}}</td>
  26. <td>{{contact.SalesName.FirstName}}</td>
  27. </tr> <br /> </table>
  28. </div>
  29. <hr /> </body>
  30. </html>
Step 6

Final result is given below.

Step 7

We are filtering Product or Sales Person Items here from data search result.