add sort to films page

This commit is contained in:
Sanjay B 2021-10-28 21:49:16 +05:30
commit cc5200fd2d
2 changed files with 40 additions and 2 deletions

15
app/static/js/films.js Normal file
View 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)
})
})