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

perf(vue-grid): optimize cell rendering #1172

Merged
merged 5 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions packages/dx-vue-grid/src/plugins/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,50 @@ import {
} from '@devexpress/dx-grid-core';

const RowPlaceholder = {
functional: true,
render(h, context) {
props: {
tableRow: {
type: Object,
required: true,
},
height: {
type: [Number, String],
},
},
render() {
return (
<DxTemplatePlaceholder
name="tableRow"
{...context.data}
{...{ attrs: { ...this.$props } }}
>
{context.children}
{this.$slots.default}
</DxTemplatePlaceholder>
);
},
};

const CellPlaceholder = {
functional: true,
render(h, context) {
props: {
tableColumn: {
type: Object,
required: true,
},
tableRow: {
type: Object,
required: true,
},
colSpan: {
type: Number,
required: true,
},
rowSpan: {
type: Number,
},
},
render() {
return (
<DxTemplatePlaceholder
name="tableCell"
{...context.data}
{...{ attrs: { ...this.$props } }}
/>
);
},
Expand Down
76 changes: 62 additions & 14 deletions packages/dx-vue-grid/src/plugins/table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,54 @@ describe('DxTable', () => {
});
});

describe('Table Layout', () => {
it('should pass cell placeholder props to cell component attrs', () => {
isDataTableCell.mockImplementation(() => true);
const tableCellArgs = {
tableRow: { row: 'row', type: 'data' },
tableColumn: { column: 'row' },
colSpan: 4,
rowSpan: 2,
};

const wrapper = mount({
render() {
return (
<DxPluginHost>
<PluginDepsToComponents deps={defaultDeps} />
<DxTable
{...{ attrs: { ...defaultProps } }}
layoutComponent={{
props: {
cellComponent: {
type: Object,
},
},
render() {
return (
<this.cellComponent
class="cell-component"
{...{ props: { ...tableCellArgs } }}
/>
);
},
}}
/>
</DxPluginHost>
);
},
});

expect(wrapper.find(defaultProps.cellComponent).vm.$attrs)
.toMatchObject(tableCellArgs);
});
});

it('should render row by using rowComponent', () => {
isDataTableRow.mockImplementation(() => true);
const tableRowArgs = {
tableRow: { row: 'row', type: 'data' },
style: {},
children: null,
height: 40,
};

const tree = mount({
Expand Down Expand Up @@ -183,7 +225,7 @@ describe('DxTable', () => {
const tableCellArgs = {
tableRow: { row: 'row' },
tableColumn: { column: { name: 'a' } },
style: {},
colSpan: 1,
};

const tree = mount({
Expand All @@ -199,7 +241,7 @@ describe('DxTable', () => {
type: Object,
},
},
render() { return <this.cellComponent {...{ attrs: { ...tableCellArgs } }} />; },
render() { return <this.cellComponent {...{ props: { ...tableCellArgs } }} />; },
}}
/>
</DxPluginHost>
Expand All @@ -222,7 +264,7 @@ describe('DxTable', () => {
const tableCellArgs = {
tableRow: { row: 'row' },
tableColumn: { column: { name: 'column', dataType: 'column' } },
style: {},
colSpan: 1,
};
const tree = mount({
render() {
Expand All @@ -237,7 +279,7 @@ describe('DxTable', () => {
type: Object,
},
},
render() { return <this.cellComponent {...{ attrs: { ...tableCellArgs } }} />; },
render() { return <this.cellComponent {...{ props: { ...tableCellArgs } }} />; },
}}
/>
</DxPluginHost>
Expand Down Expand Up @@ -287,7 +329,11 @@ describe('DxTable', () => {
});

it('should render stub cell on plugin-defined column and row intersection', () => {
const tableCellArgs = { tableRow: { row: 'row' }, tableColumn: { column: 'column' }, style: {} };
const tableCellArgs = {
tableRow: { row: 'row' },
tableColumn: { column: 'column' },
colSpan: 1,
};

const tree = mount({
render() {
Expand All @@ -302,7 +348,7 @@ describe('DxTable', () => {
type: Object,
},
},
render() { return <this.cellComponent {...{ attrs: { ...tableCellArgs } }} />; },
render() { return <this.cellComponent {...{ props: { ...tableCellArgs } }} />; },
}}
/>
</DxPluginHost>
Expand All @@ -316,7 +362,11 @@ describe('DxTable', () => {

it('should render stub header cell on plugin-defined column and row intersection', () => {
isHeaderStubTableCell.mockImplementation(() => true);
const tableCellArgs = { tableRow: { row: 'row' }, tableColumn: { column: 'column' }, style: {} };
const tableCellArgs = {
tableRow: { row: 'row' },
tableColumn: { column: 'column' },
colSpan: 1,
};

const tree = mount({
render() {
Expand All @@ -331,7 +381,7 @@ describe('DxTable', () => {
type: Object,
},
},
render() { return <this.cellComponent {...{ attrs: { ...tableCellArgs } }} />; },
render() { return <this.cellComponent {...{ props: { ...tableCellArgs } }} />; },
}}
/>
</DxPluginHost>
Expand All @@ -349,7 +399,7 @@ describe('DxTable', () => {
isNoDataTableRow.mockImplementation(() => true);
isNoDataTableCell.mockImplementation(() => true);
const tableCellArgs = {
tableRow: { row: 'row' }, tableColumn: { column: 'column' }, style: {}, colSpan: 4,
tableRow: { row: 'row' }, tableColumn: { column: 'column' }, colSpan: 4,
};

const tree = mount({
Expand All @@ -366,7 +416,7 @@ describe('DxTable', () => {
type: Object,
},
},
render() { return <this.cellComponent {...{ attrs: { ...tableCellArgs } }} />; },
render() { return <this.cellComponent {...{ props: { ...tableCellArgs } }} />; },
}}
/>
</DxPluginHost>
Expand All @@ -386,8 +436,6 @@ describe('DxTable', () => {
isNoDataTableRow.mockImplementation(() => true);
const tableRowArgs = {
tableRow: { row: 'row', type: 'nodata' },
style: {},
children: null,
};

const tree = mount({
Expand Down