import Ember from 'ember'; export default Ember.ArrayController.extend({ // Properties queryParams: ['search'], search: '', // Computed properties filteredContent: Ember.computed('search', 'model.@each.name', function() { let search = this.get('search').toLowerCase(); let pattern = new RegExp(search); return this.get('model').filter((contact) => { return pattern.test(contact.get('name').toLowerCase()); }); }), sortedContent: Ember.computed.sort('filteredContent', 'sortProperties'), sortProperties: ['name'], // Actions actions: { searchContacts() { this.transitionToRoute({ queryParams: { search: this.search } }); } } });
import Ember from 'ember'; export default Ember.ArrayController.extend({ // Properties pageSize: 10, // Computed properties totalPages: Ember.computed('model.[]', 'pageSize', function() { return Math.ceil(this.get('model.length') / this.get('pageSize')); }), pages: Ember.computed('totalPages', function() { let totalPages = this.get('totalPages'); let pages = []; for (let i = 1; i <= totalPages; i++) { pages.push({ number: i }); } return pages; }), paginatedContent: Ember.computed('model.@each', 'pageSize', 'currentPage', function() { let start = (this.get('currentPage') - 1) * this.get('pageSize'); let end = start + this.get('pageSize'); return this.get('model').slice(start, end); }), // Actions actions: { nextPage() { if (this.get('currentPage') < this.get('totalPages')) { this.set('currentPage', this.get('currentPage') + 1); } }, previousPage() { if (this.get('currentPage') > 1) { this.set('currentPage', this.get('currentPage') - 1); } } } });Both of these examples use Ember.js, a JavaScript framework for building web applications.