se precisar link do git: https://github.com/nayarawatanuki/javascript__aluraframe2
controller
NegotiationController {
this._listNegotiations = new Bind(new ListNegotiations(), new NegotiationsView($("#negotiationsView")), 'add', 'delete', 'order', 'sortReverse');
order(col) {
if(this._currentSort == col) {
this._listNegotiations.sortReverse();
} else {
this._listNegotiations.order((a, b) => a[col] - b[col]);
}
this._currentSort = col;
}
}
list
ListNegotiation {
order(col) {
this._negotiations.sort(col);
}
sortReverse() {
this._negotiations.reverse();
}
}
view
NegotiationsView {
template(model) {
return `
<table class="table table-hover table-bordered">
<thead>
<tr>
<th id="data-date">DATA</th>
<th id="data-quantity">QUANTIDADE</th>
<th id="data-value">VALOR</th>
<th id="data-volume">VOLUME</th>
</tr>
</thead>
}
}
index.js
let filterDate = document.querySelector("#data-date");
let filterQuantity = document.querySelector("#data-quantity");
let filterValue = document.querySelector("#data-value");
let filterVolume = document.querySelector("#data-volume");
filterDate.addEventListener("click", () => controller.order('date'));
filterQuantity.addEventListener("click", () => controller.order('quantity'));
filterValue.addEventListener("click", () => controller.order('value'));
filterVolume.addEventListener("click", () => controller.order('volume'));