International Sort

The CollectionView class uses the default Intl.Collator for comparing strings for sorting. This sample show how the CollectionView and JavaScript sort a list of strings with diacritics, numbers, and upper/lower case strings:

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import * as wijmo from '@grapecity/wijmo'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // show ascending sort sort(true); // // handle buttons document.querySelector('#asc').addEventListener('click', () => sort(true)); document.querySelector('#desc').addEventListener('click', () => sort(false)); // // sort with JavaScript and with CollectionView function sort(ascending) { // sort JavaScript array let items = getData(); items.sort(); if (!ascending) { items.reverse(); } // // show JavaScript sort let ol = document.querySelector('#ol-js'); ol.innerHTML = ''; items.forEach(item => { let li = document.createElement('li'); li.textContent = item; ol.appendChild(li); }); // // sort CollectionView let cv = new wijmo.CollectionView(getData(), { sortDescriptions: [new wijmo.SortDescription(null, ascending)] }); // // show CollectionView sort ol = document.querySelector('#ol-cv'); ol.innerHTML = ''; cv.items.forEach(item => { let li = document.createElement('li'); li.textContent = item; ol.appendChild(li); }); } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity CollectionView International Sort</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <button id="asc" class="btn">Sort Ascending</button> <button id="desc" class="btn">Sort Descending</button> <div class="row"> <div class="col-xs-6"> <h4> JavaScript array.sort: </h4> <ol id="ol-js"> </ol> </div> <div class="col-xs-6"> <h4> CollectionView.sort: </h4> <ol id="ol-cv"> </ol> </div> </div> </div> </body> </html> export function getData() { return [ 'aaron', 'Aaron', 'Ação', 'Acao', 'Haagen', 'Häagen', 'Hilton', 'bill', 'Bill', 'Adieu', 'a', 'A', 'b', 'B' ]; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import * as wijmo from '@grapecity/wijmo'; // import { Component, Inject, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { array: string[]; view: wijmo.CollectionView; // constructor(@Inject(DataService) private dataService: DataService) { this.array = dataService.getData(); this.view = new wijmo.CollectionView(dataService.getData()); // this.sort(true); } // sort(ascending: boolean) { // sort JavaScript array this.array.sort(); if (!ascending) { this.array.reverse(); } // // sort CollectionView this.view.sortDescriptions.clear(); this.view.sortDescriptions.push(new wijmo.SortDescription(null, ascending)); } } // @NgModule({ imports: [BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity CollectionView International Sort</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <button class="btn" (click)="sort(true)">Sort Ascending</button> <button class="btn" (click)="sort(false)">Sort Descending</button> <div class="row"> <div class="col-xs-6"> <h4> JavaScript array.sort: </h4> <ol> <ng-template ngFor let-item [ngForOf]="array"> <li>{{ item }}</li> </ng-template> </ol> </div> <div class="col-xs-6"> <h4> CollectionView.sort: </h4> <ol> <ng-template ngFor let-item [ngForOf]="view.items"> <li>{{ item }}</li> </ng-template> </ol> </div> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { return [ 'aaron', 'Aaron', 'Ação', 'Acao', 'Haagen', 'Häagen', 'Hilton', 'bill', 'Bill', 'Adieu', 'a', 'A', 'b', 'B' ]; } } <template> <div class="container-fluid"> <button class="btn" v-on:click="sort(true)">Sort Ascending</button> <button class="btn" v-on:click="sort(false)">Sort Descending</button> <div class="row"> <div class="col-xs-6"> <h4> JavaScript array.sort: </h4> <ol> <li v-for="item in array" :key="item"> {{ item }} </li> </ol> </div> <div class="col-xs-6"> <h4> CollectionView.sort: </h4> <ol> <li v-for="item in view.items" :key="item"> {{ item }} </li> </ol> </div> </div> </div> </template> <script> import "bootstrap.css"; import "@grapecity/wijmo.styles/wijmo.css"; import Vue from 'vue'; import * as wijmo from '@grapecity/wijmo'; import { getData } from './data'; new Vue({ el: '#app', data: function(){ return { array: getData(), view: new wijmo.CollectionView(getData()) } }, methods:{ sort(ascending) { // sort JavaScript array this.array.sort(); if (!ascending) { this.array.reverse(); } // // sort CollectionView this.view.sortDescriptions.clear(); this.view.sortDescriptions.push(new wijmo.SortDescription(null, ascending)); } }, mounted: function(){ this.sort(true); } }) </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity CollectionView International Sort</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getData(callback, delay) { return [ 'aaron', 'Aaron', 'Ação', 'Acao', 'Haagen', 'Häagen', 'Hilton', 'bill', 'Bill', 'Adieu', 'a', 'A', 'b', 'B' ]; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wijmo from '@grapecity/wijmo'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.sort = (ascending) => { // sort JavaScript array this.setState({ array: this.state.array.sort() }); if (!ascending) { this.setState({ array: this.state.array.reverse() }); } // // sort CollectionView this.state.view.sortDescriptions.clear(); this.state.view.sortDescriptions.push(new wijmo.SortDescription(null, ascending)); }; this.state = { array: getData(), view: new wijmo.CollectionView(getData()) }; } render() { return <div className="container-fluid"> <button className="btn" onClick={e => this.sort(true)}>Sort Ascending</button> <button className="btn" onClick={e => this.sort(false)}>Sort Descending</button> <div className="row"> <div className="col-xs-6"> <h4> JavaScript array.sort: </h4> <ol> {this.state.array.map((item) => { return <li key="item"> {item} </li>; })} </ol> </div> <div className="col-xs-6"> <h4> CollectionView.sort: </h4> <ol> {this.state.view.items.map((item) => { return <li key={item}> {item} </li>; })} </ol> </div> </div> </div>; } componentDidMount() { this.sort(true); } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> export function getData() { return [ 'aaron', 'Aaron', 'Ação', 'Acao', 'Haagen', 'Häagen', 'Hilton', 'bill', 'Bill', 'Adieu', 'a', 'A', 'b', 'B' ]; }