Sort tables
This commit is contained in:
parent
d23aa7f0ec
commit
188eadc4c1
15
index.html
15
index.html
@ -28,7 +28,10 @@
|
|||||||
</nav>
|
</nav>
|
||||||
<table class="table table-striped" v-if="series.length > 0">
|
<table class="table table-striped" v-if="series.length > 0">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nom</th>
|
<th>
|
||||||
|
<a href="#" @click="sortBy('name')">Nom</a>
|
||||||
|
<span v-if="sort_by == 'name'" :class="['glyphicon', { 'glyphicon-chevron-up': order_desc , 'glyphicon-chevron-down': !order_desc}]"></span>
|
||||||
|
</th>
|
||||||
<th>Livre(s)</th>
|
<th>Livre(s)</th>
|
||||||
<th>Auteur(s)</th>
|
<th>Auteur(s)</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -48,7 +51,10 @@
|
|||||||
</table>
|
</table>
|
||||||
<table class="table table-striped" v-if="authors.length > 0">
|
<table class="table table-striped" v-if="authors.length > 0">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nom</th>
|
<th>
|
||||||
|
<a href="#" @click="sortBy('name')">Nom</a>
|
||||||
|
<span v-if="sort_by == 'name'" :class="['glyphicon', { 'glyphicon-chevron-up': order_desc , 'glyphicon-chevron-down': !order_desc}]"></span>
|
||||||
|
</th>
|
||||||
<th>Livre(s)</th>
|
<th>Livre(s)</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="author in authors">
|
<tr v-for="author in authors">
|
||||||
@ -61,7 +67,10 @@
|
|||||||
</table>
|
</table>
|
||||||
<table class="table table-striped" v-if="books.length > 0">
|
<table class="table table-striped" v-if="books.length > 0">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Titre</th>
|
<th>
|
||||||
|
<a href="#" @click="sortBy('title')">Nom</a>
|
||||||
|
<span v-if="sort_by == 'title'" :class="['glyphicon', { 'glyphicon-chevron-up': order_desc , 'glyphicon-chevron-down': !order_desc}]"></span>
|
||||||
|
</th>
|
||||||
<th>Auteur(s)</th>
|
<th>Auteur(s)</th>
|
||||||
<th>Serie</th>
|
<th>Serie</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
69
index.js
69
index.js
@ -6,7 +6,9 @@ var app = new Vue({
|
|||||||
series: [],
|
series: [],
|
||||||
booksCount: 0,
|
booksCount: 0,
|
||||||
page: 1,
|
page: 1,
|
||||||
perpage: 20
|
perpage: 20,
|
||||||
|
sort_by: null,
|
||||||
|
order_desc: false
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
sendQuery: function(url, error, success) {
|
sendQuery: function(url, error, success) {
|
||||||
@ -52,19 +54,21 @@ var app = new Vue({
|
|||||||
seriesSuccess: function(resp) {
|
seriesSuccess: function(resp) {
|
||||||
this.series = resp;
|
this.series = resp;
|
||||||
},
|
},
|
||||||
prevPage: function() {
|
sortBy: function(col) {
|
||||||
if (this.page > 1) {
|
if (this.sort_by == col) {
|
||||||
this.page--;
|
if (this.order_desc) {
|
||||||
if (this.books.length > 0)
|
this.order_desc = false;
|
||||||
this.loadBooks();
|
this.sort_by = null;
|
||||||
if (this.authors.length > 0)
|
} else {
|
||||||
this.loadAuthors();
|
this.order_desc = true;
|
||||||
if (this.series.length > 0)
|
}
|
||||||
this.loadSeries();
|
} else {
|
||||||
|
this.order_desc = false;
|
||||||
|
this.sort_by = col;
|
||||||
}
|
}
|
||||||
|
this.reload();
|
||||||
},
|
},
|
||||||
nextPage: function() {
|
reload: function() {
|
||||||
this.page++;
|
|
||||||
if (this.books.length > 0)
|
if (this.books.length > 0)
|
||||||
this.loadBooks();
|
this.loadBooks();
|
||||||
if (this.authors.length > 0)
|
if (this.authors.length > 0)
|
||||||
@ -72,23 +76,48 @@ var app = new Vue({
|
|||||||
if (this.series.length > 0)
|
if (this.series.length > 0)
|
||||||
this.loadSeries();
|
this.loadSeries();
|
||||||
},
|
},
|
||||||
|
prevPage: function() {
|
||||||
|
if (this.page > 1) {
|
||||||
|
this.page--;
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
nextPage: function() {
|
||||||
|
this.page++;
|
||||||
|
this.reload();
|
||||||
|
},
|
||||||
|
order: function(query) {
|
||||||
|
if (this.order_desc)
|
||||||
|
return query + '&order=desc';
|
||||||
|
return query;
|
||||||
|
},
|
||||||
|
sort: function(query) {
|
||||||
|
if (this.sort_by)
|
||||||
|
return query + '&sort=' + this.sort_by;
|
||||||
|
return query;
|
||||||
|
},
|
||||||
|
paginate: function(query) {
|
||||||
|
return query + '?page=' + this.page + '&perpage=' + this.perpage;
|
||||||
|
},
|
||||||
|
params: function(url) {
|
||||||
|
return this.order(this.sort(this.paginate(url)));
|
||||||
|
},
|
||||||
loadAuthors: function() {
|
loadAuthors: function() {
|
||||||
this.sendQuery('cgi-bin/bouquins/authors?page=' + this.page + '&perpage=' + this.perpage,
|
this.sendQuery(this.params('cgi-bin/bouquins/authors'), this.stdError, this.authorsSuccess);
|
||||||
this.stdError, this.authorsSuccess);
|
|
||||||
},
|
},
|
||||||
loadBooks: function() {
|
loadBooks: function() {
|
||||||
this.sendQuery('cgi-bin/bouquins/books?page=' + this.page + '&perpage=' + this.perpage,
|
this.sendQuery(this.params('cgi-bin/bouquins/books'), this.stdError, this.booksSuccess);
|
||||||
this.stdError, this.booksSuccess);
|
|
||||||
},
|
},
|
||||||
loadSeries: function() {
|
loadSeries: function() {
|
||||||
this.sendQuery('cgi-bin/bouquins/series?page=' + this.page + '&perpage=' + this.perpage,
|
this.sendQuery(this.params('cgi-bin/bouquins/series'), this.stdError, this.seriesSuccess);
|
||||||
this.stdError, this.seriesSuccess);
|
|
||||||
},
|
},
|
||||||
showSeries: function() {
|
showSeries: function() {
|
||||||
this.books = [];
|
this.books = [];
|
||||||
this.authors = [];
|
this.authors = [];
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.perpage = 20;
|
this.perpage = 20;
|
||||||
|
this.order_desc = false;
|
||||||
|
this.sort_by = null;
|
||||||
this.loadSeries();
|
this.loadSeries();
|
||||||
},
|
},
|
||||||
showAuthors: function() {
|
showAuthors: function() {
|
||||||
@ -96,6 +125,8 @@ var app = new Vue({
|
|||||||
this.series = [];
|
this.series = [];
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.perpage = 20;
|
this.perpage = 20;
|
||||||
|
this.order_desc = false;
|
||||||
|
this.sort_by = null;
|
||||||
this.loadAuthors();
|
this.loadAuthors();
|
||||||
},
|
},
|
||||||
showBooks: function() {
|
showBooks: function() {
|
||||||
@ -103,6 +134,8 @@ var app = new Vue({
|
|||||||
this.series = [];
|
this.series = [];
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.perpage = 20;
|
this.perpage = 20;
|
||||||
|
this.order_desc = false;
|
||||||
|
this.sort_by = null;
|
||||||
this.loadBooks();
|
this.loadBooks();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user