<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script>
<script src=" https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<div ng-app="sample">
<div ng-controller="materialController">
<h1>
Method 2:
</h1>
<ol>
<li>Ampersand (&) is interpreted as text “and”.</li>
<li>Plus (+) is interpreted as text “plus”.</li>
<li>Sharp (#) is ignored.</li>
<li>Alpha/numeric/special character sequence followed by a space list before a matching sequence followed by additional alpha/numeric/special characters. E.G. West goes before Western".</li>
<li>No special treatment for Foreign Characters.</li>
<li>Special characters are not given the least priority.</li>
<li>Ignore punctuations.</li>
</ol>
<h2>
Original Result
</h2>
<ul>
<li ng-repeat="material in materials">
{{ material.name}} , {{ material.edition}}
</li>
</ul>
<h2>
Sorted Result
</h2>
<ul>
<li ng-repeat="material in materials | orderBy : ['srtName','-edition']">
{{ material.name}} , {{ material.edition}} | <small>{{material.srtName}}</small>
</li>
</ul>
</div>
</div>
CSS
body {
font-family: Arial;
}
JavaScript
var app = angular.module('sample', []);
app.controller('materialController', function($scope) {
$scope.materials = [];
function removeSpecificCharacters(text) {
var txt = text.replace(/[&]/gi, ' and ');
txt = $.trim(txt.replace(/[+]/gi, ' plus '));
txt = $.trim(txt.replace(/[#]/gi, ''));
txt = $.trim(txt.replace(/[!()_\-?;:,'".\[\]\/]/gi, '')); //ignoring punctuations
txt = $.trim(txt.replace(/\s+/g, ' '));
return txt;
};
function getMaterials() {
$scope.materials =
[{
name: 'C#: How to Program',
srtName : '',
edition:'12e'
},
{
name: '~Custom: Financial & Managerial Accounting MAL for Tulsa Community College',
srtName : '',
edition:'13e'
},
{
name: 'C#: How to Program',
srtName : '',
edition:'12e'
},
{
name: '~Custom: Financial & Managerial Accounting MAL for Tulsa Community College',
srtName : '',
edition:'13e'
},
{
name: 'C++ How to Program',
srtName : '',
edition:'12e'
},
{
name: '¡Arriba! Comunicación y Cultura, Canadian Edition Chapters 7-12',
srtName : '',
edition:'13e'
},
{
name: 'Dave James Smith',
srtName : '',
edition:'13e'
},
{
name: 'Cid James Smith',
srtName : '',
edition:'13e'
},
{
name: 'Cid James Smith',
srtName : '',
edition:'12e'
},
{
name: '%id James Smith',
srtName : '',
edition:'12e'
},{
name: '&id James Smith',
srtName : '',
edition:'12e'
},
{
name: '(id James Smith',
srtName : '',
edition:'12e'
},
{
name: '+id James Smith',
srtName : '',
edition:'12e'
},
{
name: '~id James Smith',
srtName : '',
edition:'12e'
},
{
name: '}id James Smith',
srtName : '',
edition:'12e'
},
{
name: 'aid James Smith',
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.