grafana/public/app/core/table_model.ts

49 lines
878 B
TypeScript
Raw Normal View History

2015-12-16 05:21:13 -06:00
export default class TableModel {
2015-11-03 09:19:51 -06:00
columns: any[];
rows: any[];
type: string;
columnMap: any;
constructor() {
this.columns = [];
this.columnMap = {};
this.rows = [];
this.type = 'table';
}
sort(options) {
if (options.col === null || this.columns.length <= options.col) {
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 08:48:49 -05:00
} else {
this.columns[options.col].desc = false;
}
}
addColumn(col) {
if (!this.columnMap[col.text]) {
this.columns.push(col);
this.columnMap[col.text] = col;
}
}
2015-11-03 09:19:51 -06:00
}