Skip to content

Commit

Permalink
Merge pull request #3030 from eduardmarcinco/issue/3006
Browse files Browse the repository at this point in the history
feat: allow users to delete all table rows
  • Loading branch information
zvonimirfras authored Oct 22, 2024
2 parents 7967695 + 5e3b692 commit ec69414
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/table/table-model.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,25 @@ describe("Table", () => {
expect(tableModel.header.length).toEqual(2);
});

it("should delete all rows", () => {
let tableModel = new TableModel();
tableModel.data = [
[new TableItem({data: "A"}), new TableItem({data: "B"})],
[new TableItem({data: "C"}), new TableItem({data: "D"})],
[new TableItem({data: "E"}), new TableItem({data: "F"})]
];

tableModel.deleteAllRows();

expect(tableModel.data).toEqual([[]]);
expect(tableModel.totalDataLength).toEqual(0);
// Should still equal to 1, since we default to [[]] when we set data to an empty array
expect(tableModel.rowsSelected.length).toEqual(1);
expect(tableModel.rowsContext.length).toEqual(1);
expect(tableModel.rowsExpanded.length).toEqual(1);
expect(tableModel.rowsClass.length).toEqual(1);
expect(tableModel.rowsIndices.length).toEqual(1);
});

/* ****************************************************************
*********** ***********
Expand Down
7 changes: 7 additions & 0 deletions src/table/table-model.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ export class TableModel implements PaginationModel {
this.dataChange.emit();
}

/**
* Deletes all rows.
*/
deleteAllRows() {
this.data = [];
}

hasExpandableRows() {
return this.data.some(data => data.some(d => d && d.expandedData)); // checking for some in 2D array
}
Expand Down

0 comments on commit ec69414

Please sign in to comment.