Created
July 19, 2016 14:04
-
-
Save davidpett/3bedabc31ea9a524365299a70a77ffa9 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Table from 'ember-light-table'; | |
const { | |
computed, | |
get, | |
isPresent, | |
observer, | |
set, | |
setProperties | |
} = Ember; | |
export default Ember.Component.extend({ | |
tagName: 'section', | |
classNameBindings: [ | |
':list-table' | |
], | |
columns: [], | |
dir: 'asc', | |
filterKey: '', | |
rows: [], | |
sort: null, | |
table: null, | |
title: null, | |
transitionTo: 'transitionTo', | |
filteredRows: computed('sortedRows', 'filterKey', 'columns', function() { | |
let columns = get(this, 'columns'); | |
let filterKey = get(this, 'filterKey'); | |
let rows = get(this, 'sortedRows'); | |
let filteredRows = rows.filter((row) => { | |
return columns.any((column) => { | |
let value = get(row, get(column, 'valuePath')); | |
let ret = false; | |
if (isPresent(value)) { | |
ret = value.toString().toLowerCase().indexOf(filterKey) !== -1; | |
} | |
return ret; | |
}); | |
}); | |
return filteredRows; | |
}), | |
sortAsc: true, | |
sortBy: '', | |
sortDefinition: computed('sortAsc', 'sortBy', function() { | |
let sortBy = get(this, 'sortBy'); | |
let sortOrder = get(this, 'sortAsc') ? 'asc' : 'desc'; | |
return [`${sortBy}:${sortOrder}`]; | |
}), | |
sortedRows: computed.sort('rows', 'sortDefinition'), | |
init() { | |
this._super(...arguments); | |
set(this, 'table', new Table(get(this, 'columns'), get(this, 'filteredRows'))); | |
}, | |
didUpdateAttrs() { | |
this._super(...arguments); | |
set(this, 'sortBy', ''); | |
get(this, 'table').setColumns(get(this, 'columns')); | |
}, | |
filteredRowsDidChange: observer('filteredRows', function() { | |
get(this, 'table').setRows(get(this, 'filteredRows')); | |
}), | |
actions: { | |
sortByColumn(column) { | |
if (column.sorted) { | |
let obj = { | |
sortAsc: column.ascending, | |
sortBy: get(column, 'valuePath') | |
}; | |
setProperties(this, obj); | |
} | |
} | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.6.0", | |
"ember-data": "2.6.1", | |
"ember-template-compiler": "2.6.0" | |
}, | |
"addons": { | |
"ember-light-table": "1.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment