作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 DataTables 表,其中一些标题列中有复选框和弹出窗口。 (另外我也使用FixedColumn和ColReorder插件)。我在 jsfiddle 中的模型位于底部
我的问题是,如果用户尝试检查复选框或推送弹出窗口,排序事件就会接管一切。 jsfiddle 页面无法完全运行,因为在我的应用程序中,我收到了复选框单击的事件,但当时为时已晚,排序也会发生。排序图标只是标题单元格的背景 CSS,排序事件由 DataTables 为整个标题单元格注册。
解决这个问题的计划:
http://jsfiddle.net/csabatoth/pgue1sf5/8/
var initPage = function () {
var columnsArray = [
{ "title": "index", "class": "dt-center" },
{ "title": "lastname", "class": "dt-head-center dt-body-left" },
{ "title": "firstname", "class": "dt-head-center dt-body-left" },
{ "title": '<div>foo1</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-head-center dt-body-left" },
{ "title": '<div>foo2</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-center rulecolumn" },
{ "title": '<div>foo3</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-center rulecolumn" },
{ "title": '<div>foo4</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-center rulecolumn" },
{ "title": '<div>bar1</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-center rulecolumn" },
{ "title": '<div>bar2</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-center rulecolumn" },
{ "title": '<div>bar3</div><input type="checkbox" class="filterchk" checked="checked"> <select class="paramsel"><option value="1" selected="selected"/><option value="2"/><option value="3"/></select>', "class": "dt-center rulecolumn" }
];
var dataArray = [
[ 1, "aaa", "rrr", "x", "x", "x", "x", "x", "x", "x" ],
[ 2, "bbb", "qqq", "x", "x", "x", "x", "x", "x", "x" ],
[ 3, "ccc", "ppp", "x", "x", "x", "x", "x", "x", "x" ],
[ 4, "ddd", "ooo", "x", "x", "x", "x", "x", "x", "x" ],
[ 5, "eee", "nnn", "x", "x", "x", "x", "x", "x", "x" ],
[ 6, "fff", "mmm", "x", "x", "x", "x", "x", "x", "x" ],
[ 7, "ggg", "lll", "x", "x", "x", "x", "x", "x", "x" ],
[ 8, "hhh", "kkk", "x", "x", "x", "x", "x", "x", "x" ],
[ 9, "iii", "jjj", "x", "x", "x", "x", "x", "x", "x" ]
];
viewModel.table = $('#MyTable').DataTable({
dom: "Rrtip",
autoWidth: false,
deferRender: true,
info: true,
lengthChange: false,
ordering: true,
orderMulti: true,
orderFixed: {
pre: [0, 'asc'],
post: [1, 'asc']
},
paging: true,
pagingType: "full_numbers",
renderer: "bootstrap",
processing: true,
scrollX: true,
scrollY: false,
searching: false,
columns: columnsArray,
data: dataArray,
initComplete: function (settings, json) {
viewModel.attachTableEventHandlers();
},
displayLength: 5,
colReorder: {
fixedColumnsLeft: 3,
fixedColumnsRight: 0
}
});
new $.fn.dataTable.FixedColumns(viewModel.table, {
leftColumns: 3
});
最佳答案
我只阅读了问题的标题和前 3 行(所以我希望它有帮助),但是如果您需要的只是停止单击的传播,甚至停止位于内部的单击的复选框您应该将 onclick="event.stopPropagation()"
添加到该复选框,或者更好的是在 IE(旧版)和其他浏览器上运行的函数
//taken from my yadcf plugin, you can call it in your code like this:
//yadcf.stopPropagation(event)
function stopPropagation(evt) {
if (evt.stopPropagation !== undefined) {
evt.stopPropagation();
} else {
evt.cancelBubble = true;
}
}
并在复选框中添加onclick="stopPropagation(event)"
对于您的选择,您还应该添加 onmousedown="..."
所以它看起来像这样:
<select onclick="event.stopPropagation()"
onmousedown="event.stopPropagation()"
这是一个working jsfiddle ,我只修复了第一个复选框/选择
关于jquery - DataTables:如果标题中有复选框和弹出控件,如何避免列排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25828099/
我是一名优秀的程序员,十分优秀!