Comments (4)
admin没更新最新的写法,按照官网demo的方式可以解决拖拽不准确的问题。
封装成组件不会影响相关逻辑,你无法调整列宽我猜测是tableWidthConfig参数在传递过程中变了地址,导致函数中的变动没反应到组件上。
如果使用column模式的话就不需要自己去执行resize逻辑了。
from ng-devui.
管理员没有更新最新的写法,按照官网demo的方式可以解决拖拽不准确的问题。封装 成组件不会影响相关逻辑,你无法调整列宽我猜测是tableWidthConfig参数在传递过程中变了地址,导致函数中的振动没有反应到组件上。 如果使用column模式的话就不需要自己去执行resize逻辑了。
管理员demo的写法改成如下方法可以解决拖拽不准确的问题
onResize({width, beforeWidth}: { width: number, beforeWidth: number }, field: string): void {
const index: number = this.tableWidthConfig.findIndex((config): boolean => config.field === field);
if (index > -1) {
const ratio: number = beforeWidth / parseInt(this.tableWidthConfig[index].width, 10);
this.tableWidthConfig.forEach((t, i: number): void => {
t.width = parseInt(t.width, 10) * ratio + 'px';
if (index === i) t.width = width + 'px';
});
}
}
但是需要帮忙理解一下,为什么forEach里面加一行t.width = parseInt(t.width, 10) * ratio + 'px';就能解决拖拽不准的问题
from ng-devui.
管理员没有更新最新的写法,按照官网demo的方式可以解决拖拽不准确的问题。封装 成组件不会影响相关逻辑,你无法调整列宽我猜测是tableWidthConfig参数在传递过程中变了地址,导致函数中的振动没有反应到组件上。 如果使用column模式的话就不需要自己去执行resize逻辑了。
管理员demo的写法改成如下方法可以解决拖拽不准确的问题
onResize({width, beforeWidth}: { width: number, beforeWidth: number }, field: string): void { const index: number = this.tableWidthConfig.findIndex((config): boolean => config.field === field); if (index > -1) { const ratio: number = beforeWidth / parseInt(this.tableWidthConfig[index].width, 10); this.tableWidthConfig.forEach((t, i: number): void => { t.width = parseInt(t.width, 10) * ratio + 'px'; if (index === i) t.width = width + 'px'; }); } }但是需要帮忙理解一下,为什么forEach里面加一行t.width = parseInt(t.width, 10) * ratio + 'px';就能解决拖拽不准的问题
t.width = parseInt(t.width, 10) * ratio + 'px';这个函数是把tableWidthConfig内的宽度重置为真实列宽,表格布局下,列宽不足会按比例分配,所以拖拽后宽度设置要避免做自适应分配。
另外你的写法不完善,例如拖拽后整体宽度不足的补偿没有,建议你看下组件的写法,或者直接引用相关函数使用。
from ng-devui.
管理员没有更新最新的写法,按照官网demo的方式可以解决拖拽不准确的问题。封装 成组件不会影响相关逻辑,你无法调整列宽我猜测是tableWidthConfig参数在传递过程中变了地址,导致函数中的振动没有反应到组件上。 如果使用column模式的话就不需要自己去执行resize逻辑了。
管理员demo的写法改成如下方法可以解决拖拽不准确的问题
onResize({width, beforeWidth}: { width: number, beforeWidth: number }, field: string): void { const index: number = this.tableWidthConfig.findIndex((config): boolean => config.field === field); if (index > -1) { const ratio: number = beforeWidth / parseInt(this.tableWidthConfig[index].width, 10); this.tableWidthConfig.forEach((t, i: number): void => { t.width = parseInt(t.width, 10) * ratio + 'px'; if (index === i) t.width = width + 'px'; }); } }但是需要帮忙理解一下,为什么forEach里面加一行t.width = parseInt(t.width, 10) * ratio + 'px';就能解决拖拽不准的问题
t.width = parseInt(t.width, 10) * ratio + 'px';这个函数是把tableWidthConfig内的宽度重置为真实列宽,表格布局下,列宽不足会按比例分配,所以拖拽后宽度设置要避免做自适应分配。
另外你的写法不完善,例如拖拽后整体宽度不足的补偿没有,建议你看下组件的写法,或者直接引用相关函数使用。
我看到有一个这种写法
function tableResizeFunc(tableWidthConfig, ele) {
let _totalWidth = 0;
let lastWidth = 0;
let firstResize = true;
return function onResize({ width, beforeWidth }, field) {
const index = tableWidthConfig.findIndex((config) => {
return config.field === field;
});
if (index > -1) {
if (firstResize) {
firstResize = false;
const ratio = beforeWidth / parseInt(tableWidthConfig[index].width, 10);
tableWidthConfig.forEach(t => {
t.width = parseInt(t.width, 10) * ratio + 'px';
});
_totalWidth = ele.nativeElement.querySelector('.table-wrap').offsetWidth;
lastWidth = parseInt(tableWidthConfig.slice(-1)[0].width);
}
tableWidthConfig[index].width = width + 'px';
let newWidthTotal = 0;
tableWidthConfig.forEach(t => {
newWidthTotal += parseInt(t.width, 10);
});
const lastCol = tableWidthConfig[tableWidthConfig.length - 1];
const lastColWidth = parseInt(lastCol.width, 10);
const changeValue = newWidthTotal - _totalWidth;
if (changeValue < 0) {
lastCol.width = lastColWidth + _totalWidth - newWidthTotal + 'px';
}
else if (lastColWidth > lastWidth) {
const lastChange = (lastColWidth - lastWidth) > changeValue ? changeValue : (lastColWidth - lastWidth);
lastCol.width = lastColWidth - lastChange + 'px';
}
}
};
}
在我实际的项目里面反而没有前面简化写法运行那么稳定😂,好像不需要写一个宽度补偿也可以正常使用,会自动补偿。
from ng-devui.
Related Issues (20)
- ✨ [Feature]: 补全分类输入框等示例 HOT 1
- 🐛 [Bug]: HOT 2
- ✨ [Feature]: update ng 16 HOT 2
- 🐛 [Bug]: dialog弹窗未禁止页面滚动条 HOT 1
- ✨ [Feature]: Modal 模态弹窗添加全屏功能 HOT 3
- 🐛 [Bug]: 主题功能存在bug HOT 2
- ✨ [Feature]: 能否在 Color 板块让开发者动态切换各个样式颜色,并将可见效果同步到其他板块(如“Primary 按钮样式”) HOT 1
- ✨ [Bug]: Cascader不是受控组件么?目前通过form表单 拿不到值 HOT 3
- ✨ [Feature]: ng版本data-table组件在视图模式下负责呈现单元格内容的自定义组件 HOT 2
- 🐛 [Bug]: DatePickerPro组件最外层的圆角没有设置,在有色背景下显示突兀 HOT 1
- 🐛 [Bug]: DropDown下拉菜单控制台有警告信息 HOT 2
- 🐛 [Bug]: dTextInput组件设置size不起作用 HOT 1
- ✨ [Feature]: 建议对d-casader组件增加回调函数控制是否可选 HOT 3
- Modal cssClass属性不生效🐛 [Bug]: HOT 1
- 🐛 [Bug]: tabs中签入iframe的问题 HOT 1
- 🐛 [Bug]: Transfer 穿梭框,自定义穿梭框 HOT 1
- ✨ [Feature]: Cascader勾选父级时,不带父级与子级的值 HOT 3
- 🐛 [Bug]: dialog组件,打开modal框的时候,配置buttons属性为空数组,模态框底部区域出现大片留白 HOT 1
- 🐛 [Bug]: Accordion未正确隐藏Icon标签,导致左侧不能对齐
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-devui.