Skip to content

Commit

Permalink
feat(module:st): add remove method (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 5, 2018
1 parent 62724a0 commit 13a3a21
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/abc/table/index.en-US.md
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions packages/abc/table/index.zh-CN.md
Expand Up @@ -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`
Expand Down
13 changes: 13 additions & 0 deletions packages/abc/table/table.component.ts
Expand Up @@ -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
Expand Down
51 changes: 38 additions & 13 deletions packages/abc/table/test/table.spec.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -98,7 +103,7 @@ describe('abc: table', () => {
RouterTestingModule.withRoutes([]),
NgZorroAntdModule.forRoot(),
STModule.forRoot(),
DelonLocaleModule
DelonLocaleModule,
];
const providers = [];
if (other.providers && other.providers.length) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
});
Expand All @@ -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();
});
});
Expand Down Expand Up @@ -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]', () => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 13a3a21

Please sign in to comment.