You need to sign in to do that
Don't have an account?
Brandon Barb 4
Default Sort Order with Angular?
I'm creating a VF page that allows searching/sorting of a custom object using AngularJS.
I was able to get the sorting to work, but is there a way for me to set one column to be sorted when the page is loaded?
ie. I want my Name column to be in alphabetical order when the page loads.
<script> var App = angular.module('myApp', []); App.controller('myctrl', function ($scope) { $scope.contacts = {!contacts} $scope.sort = function(keyname){ $scope.sortKey = keyname; //set the sortKey to the param passed $scope.reverse = !$scope.reverse; //if true make it false and vice versa } }); </script>
All Answers
Try this $scope.columnToOrder = 'col_1';
If this answer solves your problem then mark it as the solution to help others. Thanks.
Yes ...which will sort based on the same in this example
$scope.sortType = 'Name'; // set the default sort type
<tr ng-repeat="c in filteredContacts | orderBy:sortType:sortReverse">
<td><a href="https://toolingorg-cbpoit--toolingsand.cs32.force.com/s/detail/{{ c.Id }}"> {{ c.Name }} </a></td>
<td>{{ c.Phone }}</td>
</tr>
Complete code
Hey Raj, my code has changed quite a bit since yesterday (I'm trying to learn as much as I can in a very short amount of time).
Will I be able to just add $scope.sortType = 'Name'; // set the default sort type into my code below?
Raj - here's my controller -