feat: update table

pull/2682/head
tangjinzhou 2020-07-23 22:52:04 +08:00
parent b4980867f4
commit efb714e572
11 changed files with 54 additions and 34 deletions

@ -1 +1 @@
Subproject commit 2bead0607865ddfbb49f958507d55249b9b0f3c4 Subproject commit dd3e7a8023c35c197ff9e3fd754d6d4f8a3fc852

View File

@ -105,3 +105,11 @@ dateRender
(current: moment.Moment, today: moment.Moment) => ({current: moment.Moment, today: moment.Moment}) (current: moment.Moment, today: moment.Moment) => ({current: moment.Moment, today: moment.Moment})
monthCellContentRender (date, locale) => ({date, locale}) monthCellContentRender (date, locale) => ({date, locale})
## table
customRender( text, record, index, column ); => customRender({ text, record, index, column });
expandedRowRender(record, index, indent, expanded) => expandedRowRender({ record, index, indent, expanded })
filterIcon(filtered, column) => filterIcon({ filtered, column })

View File

@ -1,4 +1,4 @@
import { inject } from 'vue'; import { inject, markRaw } from 'vue';
import CaretUpFilled from '@ant-design/icons-vue/CaretUpFilled'; import CaretUpFilled from '@ant-design/icons-vue/CaretUpFilled';
import CaretDownFilled from '@ant-design/icons-vue/CaretDownFilled'; import CaretDownFilled from '@ant-design/icons-vue/CaretDownFilled';
import VcTable, { INTERNAL_COL_DEFINE } from '../vc-table'; import VcTable, { INTERNAL_COL_DEFINE } from '../vc-table';
@ -137,6 +137,7 @@ export default {
}, },
data() { data() {
this.vcTable = null;
// this.columns = props.columns || normalizeColumns(props.children) // this.columns = props.columns || normalizeColumns(props.children)
const props = getOptionProps(this); const props = getOptionProps(this);
warning( warning(
@ -155,7 +156,7 @@ export default {
sFilters: this.getDefaultFilters(props.columns), sFilters: this.getDefaultFilters(props.columns),
sPagination: this.getDefaultPagination(this.$props), sPagination: this.getDefaultPagination(this.$props),
pivot: undefined, pivot: undefined,
sComponents: createComponents(this.components), sComponents: markRaw(createComponents(this.components)),
filterDataCnt: 0, filterDataCnt: 0,
}; };
}, },
@ -947,7 +948,7 @@ export default {
) : null; ) : null;
}, },
renderSelectionBox(type) { renderSelectionBox(type) {
return (_, record, index) => { return ({ record, index }) => {
const rowKey = this.getRecordKey(record, index); // 1 const rowKey = this.getRecordKey(record, index); // 1
const props = this.getCheckboxPropsByItem(record, index); const props = this.getCheckboxPropsByItem(record, index);
const handleChange = e => { const handleChange = e => {

View File

@ -27,6 +27,7 @@ export default {
}), }),
data() { data() {
this.neverShown = false;
const visible = const visible =
'filterDropdownVisible' in this.column ? this.column.filterDropdownVisible : false; 'filterDropdownVisible' in this.column ? this.column.filterDropdownVisible : false;
this.preProps = { ...getOptionProps(this) }; this.preProps = { ...getOptionProps(this) };
@ -214,7 +215,7 @@ export default {
const filtered = selectedKeys && selectedKeys.length > 0; const filtered = selectedKeys && selectedKeys.length > 0;
let filterIcon = column.filterIcon; let filterIcon = column.filterIcon;
if (typeof filterIcon === 'function') { if (typeof filterIcon === 'function') {
filterIcon = filterIcon(filtered, column); filterIcon = filterIcon({ filtered, column });
} }
const dropdownIconClass = classNames({ const dropdownIconClass = classNames({
[`${prefixCls}-selected`]: 'filtered' in column ? column.filtered : filtered, [`${prefixCls}-selected`]: 'filtered' in column ? column.filtered : filtered,
@ -299,9 +300,8 @@ export default {
onDeselect={this.setSelectedKeys} onDeselect={this.setSelectedKeys}
selectedKeys={originSelectedKeys && originSelectedKeys.map(val => val.toString())} selectedKeys={originSelectedKeys && originSelectedKeys.map(val => val.toString())}
getPopupContainer={getPopupContainer} getPopupContainer={getPopupContainer}
> children={this.renderMenus(column.filters)}
{this.renderMenus(column.filters)} ></Menu>
</Menu>
<div class={`${prefixCls}-dropdown-btns`}> <div class={`${prefixCls}-dropdown-btns`}>
<a class={`${prefixCls}-dropdown-link confirm`} onClick={this.handleConfirm}> <a class={`${prefixCls}-dropdown-link confirm`} onClick={this.handleConfirm}>
{locale.filterConfirm} {locale.filterConfirm}

View File

@ -116,7 +116,7 @@ export default {
}, },
getPopupDomNode() { getPopupDomNode() {
return this.trigger.getPopupDomNode(); return this.triggerRef.getPopupDomNode();
}, },
getOpenClassName() { getOpenClassName() {
@ -133,8 +133,12 @@ export default {
const rootNode = findDOMNode(this); const rootNode = findDOMNode(this);
if (rootNode && overlayNode && rootNode.offsetWidth > overlayNode.offsetWidth) { if (rootNode && overlayNode && rootNode.offsetWidth > overlayNode.offsetWidth) {
overlayNode.style.minWidth = `${rootNode.offsetWidth}px`; overlayNode.style.minWidth = `${rootNode.offsetWidth}px`;
if (this.trigger && this.trigger._component && this.trigger._component.alignInstance) { if (
this.trigger._component.alignInstance.forceAlign(); this.triggerRef &&
this.triggerRef._component &&
this.triggerRef._component.alignInstance
) {
this.triggerRef._component.alignInstance.forceAlign();
} }
} }
} }
@ -148,7 +152,7 @@ export default {
: children; : children;
}, },
saveTrigger(node) { saveTrigger(node) {
this.trigger = node; this.triggerRef = node;
}, },
}, },

View File

@ -139,7 +139,7 @@ const BaseTable = {
}, },
render() { render() {
const { sComponents: components, prefixCls, scroll, data, getBodyWrapper } = this.table; const { sComponents: components, prefixCls, scroll, data } = this.table;
const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props; const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props;
const tableStyle = {}; const tableStyle = {};
@ -160,9 +160,6 @@ const BaseTable = {
let body; let body;
if (hasBody) { if (hasBody) {
body = <BodyWrapper class={`${prefixCls}-tbody`}>{this.renderRows(data, 0)}</BodyWrapper>; body = <BodyWrapper class={`${prefixCls}-tbody`}>{this.renderRows(data, 0)}</BodyWrapper>;
if (getBodyWrapper) {
body = getBodyWrapper(body);
}
} }
const columns = this.getColumns(); const columns = this.getColumns();
return ( return (

View File

@ -169,7 +169,9 @@ const ExpandableTable = {
return { return {
props: { colSpan: colCount }, props: { colSpan: colCount },
children: children:
fixed !== 'right' ? expandedRowRender(record, index, indent, expanded) : '&nbsp;', fixed !== 'right'
? expandedRowRender({ record, index, indent, expanded })
: '&nbsp;',
}; };
}, },
}, },

View File

@ -1,5 +1,5 @@
/* eslint-disable camelcase */ /* eslint-disable camelcase */
import { provide } from 'vue'; import { provide, markRaw } from 'vue';
import shallowequal from 'shallowequal'; import shallowequal from 'shallowequal';
import merge from 'lodash/merge'; import merge from 'lodash/merge';
import classes from 'component-classes'; import classes from 'component-classes';
@ -89,21 +89,23 @@ export default {
this.preData = [...this.data]; this.preData = [...this.data];
return { return {
columnManager: new ColumnManager(this.columns), columnManager: new ColumnManager(this.columns),
sComponents: merge( sComponents: markRaw(
{ merge(
table: 'table', {
header: { table: 'table',
wrapper: 'thead', header: {
row: 'tr', wrapper: 'thead',
cell: 'th', row: 'tr',
cell: 'th',
},
body: {
wrapper: 'tbody',
row: 'tr',
cell: 'td',
},
}, },
body: { this.components,
wrapper: 'tbody', ),
row: 'tr',
cell: 'td',
},
},
this.components,
), ),
}; };
}, },

View File

@ -70,7 +70,7 @@ export default {
let rowSpan; let rowSpan;
if (customRender) { if (customRender) {
text = customRender(text, record, index, column); text = customRender({ text, record, index, column });
if (isInvalidRenderCellText(text)) { if (isInvalidRenderCellText(text)) {
tdProps = text.props || tdProps; tdProps = text.props || tdProps;
({ colSpan, rowSpan } = tdProps); ({ colSpan, rowSpan } = tdProps);

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/date-picker/demo/index'; import demo from '../antdv-demo/docs/table/demo/ajax';
export default { export default {
components: { components: {

View File

@ -36,6 +36,9 @@ import {
TimePicker, TimePicker,
Calendar, Calendar,
DatePicker, DatePicker,
Table,
Tag,
Divider,
notification, notification,
message, message,
} from 'ant-design-vue'; } from 'ant-design-vue';
@ -89,4 +92,7 @@ app
.use(TimePicker) .use(TimePicker)
.use(Calendar) .use(Calendar)
.use(DatePicker) .use(DatePicker)
.use(Table)
.use(Tag)
.use(Divider)
.mount('#app'); .mount('#app');