Skip to content

Commit

Permalink
fix: order table asc/desc 🚑
Browse files Browse the repository at this point in the history
  • Loading branch information
iurynogueira committed Sep 18, 2023
1 parent e71c893 commit 2436da1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ describe('IonSmartTableComponent', () => {
);
});

it('should emit event sort with desc false when click in sort icon', async () => {
it('should emit event sort with desc true when click in sort icon', async () => {
const orderBy = columns[0].key;
fireEvent.click(screen.getByTestId('sort-by-' + orderBy));
expect(events).toHaveBeenCalledWith({
change_page: pagination,
event: EventTable.SORT,
order: {
column: orderBy,
desc: false,
desc: true,
},
});
});
Expand All @@ -186,7 +186,7 @@ describe('IonSmartTableComponent', () => {
fireEvent.click(screen.getByTestId('sort-by-' + orderBy));
expect(defaultProps.config.order).toStrictEqual({
column: orderBy,
desc: true,
desc: false,
});
});

Expand Down
5 changes: 3 additions & 2 deletions projects/ion/src/lib/smart-table/smart-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export class IonSmartTableComponent implements OnInit, AfterViewChecked {
}

public sort(column: Column): void {
column.desc = !column.desc;

this.config.order = {
column: column.key,
desc: column.desc,
Expand All @@ -112,7 +114,7 @@ export class IonSmartTableComponent implements OnInit, AfterViewChecked {
change_page: this.pagination,
order: {
column: column.key,
desc: !!column.desc,
desc: column.desc,
},
});

Expand All @@ -121,7 +123,6 @@ export class IonSmartTableComponent implements OnInit, AfterViewChecked {
columnEach.desc = null;
}
});
column.desc = !column.desc;
}

public handleEvent(row: SafeAny, action: ActionTable): void {
Expand Down
38 changes: 34 additions & 4 deletions projects/ion/src/lib/use-table/use-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,39 @@ interface User {
data_criacao: string;
}

const columns = [
{
key: 'data_monitoramento',
label: 'Data do monitoramento',
sort: true,
},
{
key: 'http_code',
label: 'HTTP code',
sort: true,
},
{
key: 'dns',
label: 'DNS',
sort: true,
},
{
key: 'latencia',
label: 'Conexão',
sort: true,
},
{
key: 'processamento',
label: 'Processamento',
sort: true,
},
{
key: 'problemas',
label: 'Problemas',
sort: true,
},
];

@Component({
selector: 'ion-use-table',
templateUrl: './use-table.component.html',
Expand All @@ -17,10 +50,7 @@ export class IonUseTableComponent extends BnTable<User> {
super({
service,
tableConfig: {
columns: [
{ label: 'Nome', sort: true, key: 'nome', desc: true },
{ label: 'Url', sort: true, key: 'url' },
],
columns,
actions: [
{
icon: 'trash',
Expand Down

0 comments on commit 2436da1

Please sign in to comment.