diff --git a/packages/abc/table/index.en-US.md b/packages/abc/table/index.en-US.md index 284676ef5..a08c572b1 100644 --- a/packages/abc/table/index.en-US.md +++ b/packages/abc/table/index.en-US.md @@ -74,6 +74,7 @@ Name | Description `load(pi = 1, extraParams?: any, options?: STLoadOptions)` | Load specified page `reload(extraParams?: any, options?: STLoadOptions)` | Refresh current page `reset(extraParams?: any, options?: STLoadOptions)` | Reset data and `pi` to `1`, including single multi-select, sort, filter status (Covered default state) +`removeRow(data: STData | STData[])` | Remove row `clearCheck()` | Clear all `checkbox` `clearRadio()` | Clear all `radio` `export(newData?: any[], opt?: STExportOptions)` | Export Excel and make sure you have imported `XlsxModule` diff --git a/packages/abc/table/index.zh-CN.md b/packages/abc/table/index.zh-CN.md index 4d1c5047f..87d16a9cf 100644 --- a/packages/abc/table/index.zh-CN.md +++ b/packages/abc/table/index.zh-CN.md @@ -74,6 +74,7 @@ config: STConfig `load(pi = 1, extraParams?: any, options?: STLoadOptions)` | 加载指定页 `reload(extraParams?: any, options?: STLoadOptions)` | 刷新当前页 `reset(extraParams?: any, options?: STLoadOptions)` | 重置且重新设置 `pi` 为 `1`,包含单多选、排序、过滤状态(同默认状态一并清除) +`removeRow(data: STData | STData[])` | 移除行 `clearCheck()` | 清除所有 `checkbox` `clearRadio()` | 清除所有 `radio` `export(newData?: any[], opt?: STExportOptions)` | 导出Excel,确保已经导入 `XlsxModule` diff --git a/packages/abc/table/table.component.ts b/packages/abc/table/table.component.ts index 5da564fe9..cfc7fe360 100644 --- a/packages/abc/table/table.component.ts +++ b/packages/abc/table/table.component.ts @@ -464,6 +464,19 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy { }, this.rowClickTime); } + /** 移除某行数据 */ + removeRow(data: STData | STData[]) { + if (!Array.isArray(data)) { + data = [ data ]; + } + + (data as STData[]).map(item => this._data.indexOf(item)) + .filter(pos => pos !== -1) + .forEach(pos => this._data.splice(pos, 1)); + + this.cd.detectChanges(); + } + //#endregion //#region sort diff --git a/packages/abc/table/test/table.spec.ts b/packages/abc/table/test/table.spec.ts index 8c1d100c4..74742c25b 100644 --- a/packages/abc/table/test/table.spec.ts +++ b/packages/abc/table/test/table.spec.ts @@ -17,7 +17,12 @@ import { of, Observable, Subject } from 'rxjs'; import { NgZorroAntdModule, NzPaginationComponent } from 'ng-zorro-antd'; import { ModalHelper, ALAIN_I18N_TOKEN, DatePipe } from '@delon/theme'; import { deepCopy, deepGet } from '@delon/util'; -import { DelonLocaleModule, en_US, zh_CN, DelonLocaleService } from '@delon/theme'; +import { + DelonLocaleModule, + en_US, + zh_CN, + DelonLocaleService, +} from '@delon/theme'; import { STColumn, @@ -98,7 +103,7 @@ describe('abc: table', () => { RouterTestingModule.withRoutes([]), NgZorroAntdModule.forRoot(), STModule.forRoot(), - DelonLocaleModule + DelonLocaleModule, ]; const providers = []; if (other.providers && other.providers.length) { @@ -144,11 +149,7 @@ describe('abc: table', () => { .newColumn([{ title: '', index: 'id', type: 'checkbox' }]) .then(() => { page - .expectElCount( - '.st__checkall', - 1, - 'muse be a check all', - ) + .expectElCount('.st__checkall', 1, 'muse be a check all') .expectElCount( '.st__body .ant-checkbox-wrapper', PS, @@ -258,9 +259,7 @@ describe('abc: table', () => { .expectData(1, 'checked', undefined) .click('.st__body .ant-radio-wrapper') .expectData(1, 'checked', true) - .click( - '.st__body tr[data-index="1"] .ant-radio-wrapper', - ) + .click('.st__body tr[data-index="1"] .ant-radio-wrapper') .expectData(1, 'checked', false); done(); }); @@ -434,7 +433,9 @@ describe('abc: table', () => { page .newColumn([{ title: '', index: 'yn', type: 'yn' }]) .then(() => { - page.expectCell('是', 1, 1, '', true).expectCell('否', 2, 1, '', true); + page + .expectCell('是', 1, 1, '', true) + .expectCell('否', 2, 1, '', true); done(); }); }); @@ -444,7 +445,9 @@ describe('abc: table', () => { { title: '', index: 'yn', type: 'yn', ynYes: 'Y', ynNo: 'N' }, ]) .then(() => { - page.expectCell('Y', 1, 1, '', true).expectCell('N', 2, 1, '', true); + page + .expectCell('Y', 1, 1, '', true) + .expectCell('N', 2, 1, '', true); done(); }); }); @@ -1210,6 +1213,28 @@ describe('abc: table', () => { }); }); }); + describe('#removeRow', () => { + beforeEach(() => { + genModule({ minColumn: true }); + fixture.detectChanges(); + }); + it('shoule be working', done => { + fixture.whenStable().then(() => { + page.expectCurrentPageTotal(PS); + comp.removeRow(comp._data[0]); + page.expectCurrentPageTotal(PS - 1); + done(); + }); + }); + it('shoule be ingored invalid data', done => { + fixture.whenStable().then(() => { + page.expectCurrentPageTotal(PS); + comp.removeRow([null]); + page.expectCurrentPageTotal(PS); + done(); + }); + }); + }); }); describe('[row events]', () => { @@ -1502,7 +1527,7 @@ describe('abc: table', () => { row: number = 1, column: number = 1, cls?: string, - isContain?: boolean + isContain?: boolean, ): this { let cell = this.getCell(row, column); if (cls) {