2015-11-02 20:51:49 +01:00
|
|
|
|
2015-12-16 12:21:13 +01:00
|
|
|
export default class TableModel {
|
2015-11-03 16:19:51 +01:00
|
|
|
columns: any[];
|
|
|
|
rows: any[];
|
2015-12-03 15:09:39 +01:00
|
|
|
type: string;
|
2015-11-02 20:51:49 +01:00
|
|
|
|
2015-11-05 08:36:51 +01:00
|
|
|
constructor() {
|
|
|
|
this.columns = [];
|
|
|
|
this.rows = [];
|
2015-12-03 15:09:39 +01:00
|
|
|
this.type = 'table';
|
2015-11-05 08:36:51 +01:00
|
|
|
}
|
|
|
|
|
2015-11-09 17:58:02 +01:00
|
|
|
sort(options) {
|
2015-11-12 12:39:16 +01:00
|
|
|
if (options.col === null || this.columns.length <= options.col) {
|
2015-11-09 17:58:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rows.sort(function(a, b) {
|
|
|
|
a = a[options.col];
|
|
|
|
b = b[options.col];
|
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a > b) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.columns[options.col].sort = true;
|
|
|
|
|
|
|
|
if (options.desc) {
|
|
|
|
this.rows.reverse();
|
|
|
|
this.columns[options.col].desc = true;
|
2016-04-28 15:48:49 +02:00
|
|
|
} else {
|
|
|
|
this.columns[options.col].desc = false;
|
2015-11-09 17:58:02 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-03 16:19:51 +01:00
|
|
|
}
|