Skip to content

Commit 90c4577

Browse files
authored
fix(Table): can not resize table column when set ShowDetails to true (#1481)
* refactor: 增加 tables 变量 * feat: 实现拖动逻辑 * chore: bump version 7.8.0
1 parent d6e519f commit 90c4577

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>7.7.8-beta05</Version>
4+
<Version>7.8.0</Version>
55
</PropertyGroup>
66

77
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

src/BootstrapBlazor/Components/Table/Table.razor.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,28 @@ const setResizeListener = table => {
179179
else th.classList.remove('border-resize')
180180

181181
const index = [].indexOf.call(th.parentNode.children, th);
182-
th.closest('.table-resize').querySelectorAll('.table > tbody > tr').forEach(tr => {
183-
if (!tr.classList.contains('is-detail')) {
184-
const td = tr.children.item(index)
185-
if (toggle) td.classList.add('border-resize')
186-
else {
187-
td.classList.remove('border-resize')
188-
if (td.classList.length == 0) {
189-
td.removeAttribute('class')
182+
const rows = []
183+
table.tables.forEach(t => {
184+
const body = [...t.children].filter(i => i.nodeName === 'TBODY')
185+
if (body.length > 0) {
186+
const tr = [...body[0].children].filter(i => i.nodeName === 'TR')
187+
tr.forEach(i => {
188+
if (!i.classList.contains('is-detail')) {
189+
rows.push(i)
190190
}
191+
})
192+
}
193+
})
194+
rows.forEach(tr => {
195+
const td = tr.children.item(index)
196+
if (toggle) td.classList.add('border-resize')
197+
else {
198+
td.classList.remove('border-resize')
199+
if (td.classList.length == 0) {
200+
td.removeAttribute('class')
191201
}
192202
}
193-
});
203+
})
194204
return index
195205
}
196206

@@ -214,7 +224,8 @@ const setResizeListener = table => {
214224
drag(col,
215225
e => {
216226
colIndex = eff(col, true)
217-
const currentCol = el.querySelectorAll('table colgroup col')[colIndex]
227+
const table = col.closest('table')
228+
const currentCol = table.querySelectorAll('colgroup col')[colIndex]
218229
const width = currentCol.style.width
219230
if (width) {
220231
colWidth = parseInt(width)
@@ -226,14 +237,16 @@ const setResizeListener = table => {
226237
},
227238
e => {
228239
const marginX = e.clientX - originalX
229-
el.querySelectorAll('table colgroup').forEach(group => {
240+
table.tables.forEach(t => {
241+
const group = [...t.children].filter(i => i.nodeName === 'COLGROUP')[0]
230242
const curCol = group.children.item(colIndex)
231243
curCol.style.width = `${colWidth + marginX}px`
232244
const tableEl = curCol.closest('table')
233245
const width = tableWidth + marginX
234-
if (table.fixedHeader) {
246+
if (t.classList.contains('table-fixed')) {
235247
tableEl.style.width = `${width}px;`
236-
} else {
248+
}
249+
else {
237250
tableEl.style.width = (width - 6) + 'px'
238251
}
239252
})
@@ -326,20 +339,26 @@ export function init(id) {
326339
fixedHeader: el.querySelector('.table-fixed') != null,
327340
isExcel: el.querySelector('.table-excel') != null,
328341
isResizeColumn: el.querySelector('.col-resizer') != null,
329-
columns: []
342+
columns: [],
343+
tables: []
330344
}
331345
Data.set(id, table)
332346

333347
if (table.fixedHeader) {
334348
table.thead = el.querySelector('.table-fixed-header')
335349
table.body = el.querySelector('.table-fixed-body')
350+
table.tables.push(table.thead.children[0])
351+
table.tables.push(table.body.children[0])
336352
fixHeader(table)
337353

338354
EventHandler.on(table.body, 'scroll', () => {
339355
const left = table.body.scrollLeft
340356
table.thead.scrollTo(left, 0)
341357
});
342358
}
359+
else {
360+
table.tables.push(table.el.querySelector('.table-wrapper').children[0])
361+
}
343362

344363
if (table.isExcel) {
345364
setExcelKeyboardListener(table)

0 commit comments

Comments
 (0)