Skip to content

Commit

Permalink
优化树形表格
Browse files Browse the repository at this point in the history
  • Loading branch information
peng92055 committed May 6, 2020
1 parent 06fbfac commit e326621
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [1.2.3](https://github.com/peng92055/smart-table/tree/1.2.3) (2020-05-06)

[Full Changelog](https://github.com/peng92055/smart-table/compare/1.2.2...1.2.3)

- 优化树形表格含有非法expand-parent
- 优化树形表格支持自定义高度控制
- 修复expand中多标签bug

## [1.2.2](https://github.com/peng92055/smart-table/tree/1.2.2) (2020-02-19)

[Full Changelog](https://github.com/peng92055/smart-table/compare/1.2.1...1.2.2)
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = merge(common, {
inject: 'head'
})
],
devtool: 'inline-source-map',
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: './examples'
}
Expand Down
1 change: 1 addition & 0 deletions config/webpack.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = merge(common, {
}
}],
},
devtool: 'cheap-module-source-map',
plugins: [
new CleanWebpackPlugin(),
new webpack.BannerPlugin(`smartTable v${pkg.version} | (c) pengyajun 2020 | Released under the MIT License.`),
Expand Down
1 change: 1 addition & 0 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = merge(common, {
}
}],
},
devtool: 'cheap-module-source-map',
plugins: [
new CleanWebpackPlugin(),
new webpack.BannerPlugin(`smartTable v${pkg.version} | (c) pengyajun 2020 | Released under the MIT License.`)
Expand Down
3 changes: 2 additions & 1 deletion dist/smartTable.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/smartTable.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions lib/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function layout(vm, table) {
height: tbodyWrapperHeight + "px"
})


vm.size.tbodyWrapperHeight = tbodyWrapperHeight;

//垂直方向是否有滚动条
Expand Down Expand Up @@ -667,25 +668,28 @@ function initExpand(vm, tbody) {
const expandAll = vm.options.defaultExpandAll;
let data = [];
let parents = [];
let parentIds = [];
querySelectorAll(tbody, "tr").forEach(row => {
let paddingLength = parents.length;
let expand = hasAttribute(row, "expand");
let hasParent = hasAttribute(row, "expand-parent");
let expandParentId = getAttribute(row, "expand-parent");
if (parentIds.indexOf(expandParentId) === -1) {
hasParent = false;
}
let node = {
$el: row,
id: getAttribute(row, "expand"),
expand: expand
};
if (expand) {
if (expandAll) {
setAttribute(row, 'expanded')
} else {
removeAttribute(row, 'expanded')
}
expandAll ? setAttribute(row, 'expanded') : removeAttribute(row, 'expanded');
}

if (expand && !hasParent) {
node.children = [];
parents = [node];
parentIds.push(node.id)
data.push(node);
} else if (hasParent) {
let parentId = getAttribute(row, "expand-parent");
Expand All @@ -702,6 +706,7 @@ function initExpand(vm, tbody) {
parent && parent.children.push(node);
if (expand) {
parents.push(node)
parentIds.push(node.id)
node.children = [];
}
} else {
Expand All @@ -720,6 +725,9 @@ function initExpand(vm, tbody) {
styled(vm.$tbodyWrapper, {
height: ''
})
styled(vm.$tbodyWrapper, {
maxHeight: vm.size.tbodyWrapperHeight + 'px'
})
}

function initData(vm, tbody) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-table",
"version": "1.2.2",
"version": "1.2.3",
"description": "smart table for static html",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e326621

Please sign in to comment.