Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:st): add expandRowByClick property #326

Merged
merged 5 commits into from Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions .editorconfig
@@ -1,7 +1,15 @@
# http://editorconfig.org

root = true

[*]
charset=utf-8
end_of_line=lf
trim_trailing_whitespace=true
insert_final_newline=false
indent_style=space
indent_size=2
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -59,7 +59,7 @@
"file-saver": "^2.0.0",
"marked": "^0.5.2",
"ng-github-button": "^2.0.0",
"ng-zorro-antd": "^7.0.0-rc.0",
"ng-zorro-antd": "^7.0.0-rc.1",
"ng2-ace-editor": "^0.3.8",
"ngx-color": "^2.0.5",
"ngx-countdown": "^3.1.0",
Expand Down Expand Up @@ -143,4 +143,4 @@
"commit-msg": "node ./scripts/git/commit-msg.js -E HUSKY_GIT_PARAMS"
}
}
}
}
2 changes: 1 addition & 1 deletion packages/abc/table/demo/expand.md
Expand Up @@ -20,7 +20,7 @@ import { STColumn } from '@delon/abc';
@Component({
selector: 'app-demo',
template: `
<st [data]="users" [columns]="columns" [expand]="expand">
<st [data]="users" [columns]="columns" [expand]="expand" expandRowByClick>
<ng-template #expand let-item let-index="index" let-column="column">
{{ item.description }}
</ng-template>
Expand Down
1 change: 1 addition & 0 deletions packages/abc/table/index.en-US.md
Expand Up @@ -59,6 +59,7 @@ Property | Description | Type | Default
`[header]` | Table header renderer | `string,TemplateRef<void>` | -
`[footer]` | Table footer renderer | `string,TemplateRef<void>` | -
`[body]` | Table extra body renderer, generally used to add total rows | `TemplateRef<void>` | -
`[expandRowByClick]` | Whether to expand row by clicking anywhere in the whole row | `boolean` | `false`
`[expand]` | Whether current column include expand icon | `TemplateRef<void>` | -
`(change)` | Events | `EventEmitter<STChange>` | -
`(error)` | Error event | `EventEmitter<STError>` | -
Expand Down
1 change: 1 addition & 0 deletions packages/abc/table/index.zh-CN.md
Expand Up @@ -59,6 +59,7 @@ config: STConfig
`[header]` | 表格标题 | `string,TemplateRef<void>` | -
`[footer]` | 表格底部 | `string,TemplateRef<void>` | -
`[body]` | 表格额外内容,一般用于添加合计行 | `TemplateRef<void>` | -
`[expandRowByClick]` | 通过点击行来展开子行 | `boolean` | `false`
`[expand]` | 当前列是否包含展开按钮,当数据源中包括 `expand` 表示展开状态 | `TemplateRef<void>` | -
`(change)` | 变化时回调,包括:`pi`、`ps`、`checkbox`、`radio`、`sort`、`filter`、`click`、`dblClick` 变动 | `EventEmitter<STChange>` | -
`(error)` | 异常时回调 | `EventEmitter<STError>` | -
Expand Down
11 changes: 2 additions & 9 deletions packages/abc/table/table-column-source.ts
Expand Up @@ -111,19 +111,12 @@ export class STColumnSource {
// left width
list
.filter(w => w.fixed && w.fixed === 'left' && w.width)
.forEach(
(item, idx) =>
(item._left = list.slice(0, idx).reduce(countReduce, 0) + 'px'),
);
.forEach((item, idx) => (item._left = list.slice(0, idx).reduce(countReduce, 0) + 'px'));
// right width
list
.filter(w => w.fixed && w.fixed === 'right' && w.width)
.reverse()
.forEach(
(item, idx) =>
(item._right =
(idx > 0 ? list.slice(-idx).reduce(countReduce, 0) : 0) + 'px'),
);
.forEach((item, idx) => (item._right = (idx > 0 ? list.slice(-idx).reduce(countReduce, 0) : 0) + 'px'));
}

private sortCoerce(item: STColumn): STSortMap {
Expand Down
5 changes: 1 addition & 4 deletions packages/abc/table/table-data-source.ts
Expand Up @@ -156,10 +156,7 @@ export class STDataSource {
pi: retPi,
total: retTotal,
list: retList,
pageShow:
typeof page.show === 'undefined'
? (retTotal || total) > ps
: page.show,
pageShow: typeof page.show === 'undefined' ? (retTotal || total) > ps : page.show,
});
});
});
Expand Down
8 changes: 7 additions & 1 deletion packages/abc/table/table.component.ts
Expand Up @@ -127,6 +127,7 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy {
@Input() footer: string | TemplateRef<void>;
/** 额外 `body` 内容 */
@Input() body: TemplateRef<void>;
@Input() @InputBoolean() expandRowByClick = false;
/** `expand` 可展开,当数据源中包括 `expand` 表示展开状态 */
@Input() expand: TemplateRef<{ $implicit: {}; column: STColumn }>;
@Input() noResult: string | TemplateRef<void>;
Expand Down Expand Up @@ -336,6 +337,11 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy {
private rowClickCount = 0;
_rowClick(e: Event, item: STData, index: number) {
if ((e.target as HTMLElement).nodeName === 'INPUT') return;
const { expand, expandRowByClick, rowClickTime } = this;
if (!!expand && expandRowByClick) {
item.expand = !item.expand;
return;
}
++this.rowClickCount;
if (this.rowClickCount !== 1) return;
setTimeout(() => {
Expand All @@ -346,7 +352,7 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy {
this.changeEmit('dblClick', data);
}
this.rowClickCount = 0;
}, this.rowClickTime);
}, rowClickTime);
}

/** 移除某行数据 */
Expand Down
4 changes: 4 additions & 0 deletions packages/abc/table/table.config.ts
Expand Up @@ -121,4 +121,8 @@ export class STConfig {
* 表格行的类名
*/
rowClassName?: STRowClassName;
/**
* 通过点击行来展开子行
*/
expandRowByClick ?= false;
}