Title: Sort by and Search the Content
Description: "Sort by" and "Search" the Content on List data.
Steps:
Step1:
Create the list name "Infolist" and create the columns like below.
Step2:
Step3: add "Script Editer" webpart.
Step4: Add below code to Script Edit webpart
Code:
- <style>
- th {
- background-color: #0000FF;
- color: white;
- }
- </style>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
- <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
- <script>
- var myAngApp = angular.module('SharePointAngApp', []);
- myAngApp.controller('spCustomerController', function ($scope, $http) {
- $http({
- method: 'GET',
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Infolist')/items?$select=Title,Employee,Company",
- headers: { "Accept": "application/json;odata=verbose" }
- }).success(function (data, status, headers, config) {
- $scope.customers = data.d.results;
- $scope.mySortFunction = function(customer) {//Sorting Iteam
- if(isNaN(customer[$scope.sortExpression]))
- return customer[$scope.sortExpression];
- return parseInt(customer[$scope.sortExpression]);
- }
- }).error(function (data, status, headers, config) {
- });
- });
- </script>
- <br /><br />
- <div ng-app="SharePointAngApp" class="row">
- <div ng-controller="spCustomerController" class="span10">
- <div>
- Sort by:
- <select ng-model="sortExpression">
- <option value="Title">Title</option>
- <option value="Employee">Employee</option>
- <option value="Company">Company</option>
- </select>
- </div>
- <br />
- Search By Any:
- <input type="text" ng-model="search.$" />
- <br />
- <br />
- <table class="table table-condensed table-hover">
- <tr>
- <th>Title</th>
- <th>Employee</th>
- <th>Company</th>
- </tr>
- <tr ng-repeat="customer in customers | orderBy:mySortFunction | filter:search">
- <td>{{customer.Title}}</td>
- <td>{{customer.Employee}}</td>
- <td>{{customer.Company}}</td>
- </tr>
- </table>
- </div>
- </div>
OutPut:
Enter the data, it displays based on input which you gave in textbox.