add sort to films page
This commit is contained in:
parent
c5935474ad
commit
cc5200fd2d
2 changed files with 40 additions and 2 deletions
15
app/static/js/films.js
Normal file
15
app/static/js/films.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
document.getElementById('sort-select').addEventListener('change', function () {
|
||||
const sortValue = this.value
|
||||
const $films = [...document.querySelectorAll('.film')]
|
||||
console.log('$films', $films)
|
||||
$films.sort((a, b) => {
|
||||
console.log('a', a)
|
||||
const aVal = a.dataset[sortValue]
|
||||
const bVal = b.dataset[sortValue]
|
||||
return aVal < bVal ? -1 : 1
|
||||
})
|
||||
document.getElementById('films').innerHTML = ''
|
||||
$films.forEach($film => {
|
||||
document.getElementById('films').appendChild($film)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue