mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
40 lines
700 B
TypeScript
40 lines
700 B
TypeScript
|
|
export default class TableModel {
|
|
columns: any[];
|
|
rows: any[];
|
|
type: string;
|
|
|
|
constructor() {
|
|
this.columns = [];
|
|
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;
|
|
} else {
|
|
this.columns[options.col].desc = false;
|
|
}
|
|
}
|
|
}
|