Csa*_*oth 1 jquery datatables twitter-bootstrap
我有一个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
});
Run Code Online (Sandbox Code Playgroud)
我只阅读了问题的标题和它的前三行(所以我希望它有所帮助),但是如果你需要的只是停止点击的传播,即使是位于表头内的点击复选框也是如此你应该添加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;
}
}
Run Code Online (Sandbox Code Playgroud)
并在您的复选框中添加 onclick="stopPropagation(event)"
对于你的选择,你也应该添加onmousedown="..."它看起来像这样:
<select onclick="event.stopPropagation()"
onmousedown="event.stopPropagation()"
Run Code Online (Sandbox Code Playgroud)
这是一个工作的jsfiddle,我只修复了第一个复选框/选择
| 归档时间: |
|
| 查看次数: |
3378 次 |
| 最近记录: |