Skip to content

Commit f0e12e2

Browse files
committed
修复固定列td元素点击事件无法触发的问题
1 parent a5fd46c commit f0e12e2

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

dist/extensions/fixed-columns/bootstrap-table-fixed-columns.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@
177177
return;
178178
}
179179
if (arguments[0] === 'post-header') {
180-
if (!this.$fixedColumns && !this.$fixedColumnsRight) {
181-
this.initFixedContainer();
182-
}
183180
this.initFixedColumnsHeader();
184181
} else if (arguments[0] === 'scroll-body') {
185182
if (this.needFixedColumns && this.options.fixedNumber) {
@@ -385,6 +382,17 @@
385382
//给鼠标滑轮绑定事件
386383
updateScroll(e, that.$fixedBody[0]);
387384
});
385+
//给固定表格的checkbox绑定事件
386+
this.$fixedBody.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
387+
e.stopImmediatePropagation();
388+
var index = $(e.target).data("index");
389+
$(that.$selectItem[index]).trigger("click");
390+
});
391+
//绑定TD点击事件
392+
this.$fixedBody.find('> table > tbody > tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
393+
var index = $(this).closest("tr[data-index]").data("index");
394+
$(that.$selectItem[index]).closest("tr[data-index]").find(">td:eq(" + $(this).index() + ")").trigger("click");
395+
});
388396
}
389397
//给原本表格绑定scroll事件
390398
$('div.fixed-table-body').off('scroll'); //给所有的body解绑 scroll
@@ -416,11 +424,16 @@
416424
updateScroll(e, that.$fixedBodyRight[0]);
417425
});
418426
//给固定表格的checkbox绑定事件
419-
this.$fixedBody && this.$fixedBody.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
427+
this.$fixedBodyRight.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
420428
e.stopImmediatePropagation();
421429
var index = $(e.target).data("index");
422430
$(that.$selectItem[index]).trigger("click");
423431
});
432+
//绑定TD点击事件
433+
this.$fixedBodyRight.find('> table > tbody > tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
434+
var index = $(this).closest("tr[data-index]").data("index");
435+
$(that.$selectItem[index]).closest("tr[data-index]").find(">td:eq(" + $(this).index() + ")").trigger("click");
436+
});
424437
}
425438

426439
if (this.options.filterControl) {

src/extensions/fixed-columns/bootstrap-table-fixed-columns.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@
177177
return;
178178
}
179179
if (arguments[0] === 'post-header') {
180-
if (!this.$fixedColumns && !this.$fixedColumnsRight) {
181-
this.initFixedContainer();
182-
}
183180
this.initFixedColumnsHeader();
184181
} else if (arguments[0] === 'scroll-body') {
185182
if (this.needFixedColumns && this.options.fixedNumber) {
@@ -385,6 +382,17 @@
385382
//给鼠标滑轮绑定事件
386383
updateScroll(e, that.$fixedBody[0]);
387384
});
385+
//给固定表格的checkbox绑定事件
386+
this.$fixedBody.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
387+
e.stopImmediatePropagation();
388+
var index = $(e.target).data("index");
389+
$(that.$selectItem[index]).trigger("click");
390+
});
391+
//绑定TD点击事件
392+
this.$fixedBody.find('> table > tbody > tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
393+
var index = $(this).closest("tr[data-index]").data("index");
394+
$(that.$selectItem[index]).closest("tr[data-index]").find(">td:eq(" + $(this).index() + ")").trigger("click");
395+
});
388396
}
389397
//给原本表格绑定scroll事件
390398
$('div.fixed-table-body').off('scroll'); //给所有的body解绑 scroll
@@ -416,11 +424,16 @@
416424
updateScroll(e, that.$fixedBodyRight[0]);
417425
});
418426
//给固定表格的checkbox绑定事件
419-
this.$fixedBody && this.$fixedBody.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
427+
this.$fixedBodyRight.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
420428
e.stopImmediatePropagation();
421429
var index = $(e.target).data("index");
422430
$(that.$selectItem[index]).trigger("click");
423431
});
432+
//绑定TD点击事件
433+
this.$fixedBodyRight.find('> table > tbody > tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
434+
var index = $(this).closest("tr[data-index]").data("index");
435+
$(that.$selectItem[index]).closest("tr[data-index]").find(">td:eq(" + $(this).index() + ")").trigger("click");
436+
});
424437
}
425438

426439
if (this.options.filterControl) {

0 commit comments

Comments
 (0)