You need to sign in to do that
Don't have an account?
Brandon Barb 4
Filter a column with Angular?
I am creating a VF page that displays an object and allows searching of the list with Angular.
What I would like to do now is add the capability to filter on a column before searching. For example - A dropdown menu for "Department" that lists the different departments, upon selection the list filters every record with DepartmentA, then search.
How would I go about doing this?
I will eventually integrate this with custom objects, but I am using the Contact object for now until I can figure it out.
Thank you for any help you can provide.
Controller:
public with sharing class con_Test { public static String getContacts() { return JSON.serialize([select id, name, department from contact ]); } }
VF:
apex:page showHeader="false" applyHtmlTag="false" docType="html-5.0" controller="con_Test"> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script> <script> var App = angular.module('myApp', []); App.controller('myctrl', function ($scope) { $scope.contacts = {!contacts} }); </script> </head> <form class="form-inline"> <div class="form-group"> <label >Search: </label> <input type="text" ng-model="search" class="form-control" placeholder="Search"></input> </div> </form> <body ng-app="myApp" class="container" ng-controller="myctrl"> <table class="table table-bordered"> <tr> <th>Name</th> <th>Department</th> <th>Id</th> </tr> <tr ng-repeat="contact in contacts | filter:search"> <td>{{contact.Name}}</td> <td>{{contact.Department}}</td> <td>{{contact.Id}}</td> </tr> </table> </body> </apex:page>
All Answers
Do you want to show all unique department as dropdown and you want the filter on top of it?
Hey Raj, I figured out a way to get dropdowns for multiple columns, but they overwrite each other. Is it possible to have them work in conjunction?
For example - I want to select the dropdown for Department, then select a dropdown for Name, and then search.
Controller:
VF: