diff --git a/public/app/core/specs/table_model.test.ts b/public/app/core/specs/table_model.test.ts index 3c777e2ef8a..7558e35f44c 100644 --- a/public/app/core/specs/table_model.test.ts +++ b/public/app/core/specs/table_model.test.ts @@ -55,6 +55,34 @@ describe('when sorting table asc', () => { }); }); +describe('when sorting table with cols being undefined', () => { + let table: TableModel; + const panel = { + sort: { cols: undefined, desc: false }, + }; + + beforeEach(() => { + table = new TableModel(); + // @ts-ignore + table.columns = [{}, {}]; + table.rows = [ + [100, 11], + [105, 15], + [103, 10], + ]; + // This is needed because after 8.3 cols can be undefined + // https://github.com/grafana/grafana/issues/44127 + //@ts-ignore + table.sort(panel.sort); + }); + + it('should return the original table without sorting', () => { + expect(table.rows[0][1]).toBe(11); + expect(table.rows[1][1]).toBe(15); + expect(table.rows[2][1]).toBe(10); + }); +}); + describe('when sorting with nulls', () => { let table: TableModel; let values; diff --git a/public/app/core/table_model.ts b/public/app/core/table_model.ts index 1929473e69d..f2c83e40aa2 100644 --- a/public/app/core/table_model.ts +++ b/public/app/core/table_model.ts @@ -41,7 +41,8 @@ export default class TableModel implements TableData { } sort(options: { col: number; desc: boolean }) { - if (options.col === null || this.columns.length <= options.col) { + // Since 8.3.0 col property can be also undefined, https://github.com/grafana/grafana/issues/44127 + if (options.col === null || options.col === undefined || this.columns.length <= options.col) { return; }