Skip to content

Commit

Permalink
fix(module:st): should recalculate no value when call removeRow method (
Browse files Browse the repository at this point in the history
#331)

- close #330
  • Loading branch information
cipchk authored Dec 20, 2018
1 parent 9d533cf commit 6c8c2d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/abc/table/demo/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class DemoComponent {
};
});
columns: STColumn[] = [
{ title: '序号', type: 'no' },
{ title: '编号', index: 'id' },
{ title: '姓名', index: 'name' },
{ title: '年龄', index: 'age' },
Expand Down
2 changes: 2 additions & 0 deletions packages/abc/table/table-column-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class STColumnSource {
const { noIndex } = this.cog;
let checkboxCount = 0;
let radioCount = 0;
let point = 0;
const columns: STColumn[] = [];
const copyColumens = deepCopy(list) as STColumn[];
for (const item of copyColumens) {
Expand Down Expand Up @@ -298,6 +299,7 @@ export class STColumnSource {
// restore custom row
this.restoreRender(item);

item.__point = point++;
columns.push(item);
}
if (checkboxCount > 1) {
Expand Down
5 changes: 5 additions & 0 deletions packages/abc/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy {
.filter(pos => pos !== -1)
.forEach(pos => this._data.splice(pos, 1));

// recalculate no
this._columns
.filter(w => w.type === 'no')
.forEach(c => this._data.forEach((i, idx) => i._values[c.__point] = c.noIndex + idx));

this.cd();
}

Expand Down
14 changes: 11 additions & 3 deletions packages/abc/table/test/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,18 +1349,26 @@ describe('abc: table', () => {
}));
});
describe('#removeRow', () => {
beforeEach(() => {
fixture.detectChanges();
});
it('shoule be working', done => {
fixture.detectChanges();
fixture.whenStable().then(() => {
page.expectCurrentPageTotal(PS);
comp.removeRow(comp._data[0]);
page.expectCurrentPageTotal(PS - 1);
done();
});
});
it('shoule be recalculate no value', done => {
page.newColumn([ { title: '', type: 'no' } ]).then(() => {
page.expectCurrentPageTotal(PS);
comp._data.forEach((v, idx) => expect(v._values[0]).toBe(idx + 1));
comp.removeRow(comp._data[0]);
comp._data.forEach((v, idx) => expect(v._values[0]).toBe(idx + 1));
done();
});
});
it('shoule be ingored invalid data', done => {
fixture.detectChanges();
fixture.whenStable().then(() => {
page.expectCurrentPageTotal(PS);
comp.removeRow([null]);
Expand Down

0 comments on commit 6c8c2d1

Please sign in to comment.