如何禁用拖放 jquery 数据表
How to disable drag and drop on jquery datatables
所以我使用 jquery 数据 table 和 colReorder
来设置 table。此 table 具有一些功能,例如如何单击列 header 和 select 列以进行切换。为了使此功能正常工作,我必须启用 colReorder
。现在唯一的问题是,我所有的列都是可拖动的。我该如何解决这个问题?
这是我试过的方法
- 将
draggable
设置为 false
- 将
bsort
设置为 false
- 将
bsortable
设置为 false
请让我知道我做错了什么。另外,这是我的构造函数:
window.table =
$table.DataTable({
data: window.apiData['data'],
/**
dat
* Specify which columns we're going to show
*/
columns: window.columnMapping,
/**
* we want to disable showing page numbers, but still limit the number of results
*/
dom: "t",
/**
* let's disable some dynamic custom css
*/
asStripClasses: [],
/**
* let's keep the pages reasonable to prevent scrolling
*/
pageLength: 8,
/**
* this helps with hotswapping columns
*/
colReorder: true
});
谢谢!
您可以将 ColReorders 事件绑定覆盖到 <th>
元素。幸运的是,这些事件使用命名空间进行了丰富,因此可以很容易地追踪到它们,事实证明 ColReorder.mousedown
负责触发列拖动。所以你可以通过
重置功能
function resetColReorderMD() {
$('.dataTable thead th').each(function() {
var md = $._data($(this)[0]).events.mousedown;
for (var i=0, l=md.length; i<l; i++) {
if (md[i].namespace == 'ColReorder') {
md[i].handler = function() {}
}
}
})
}
$('#example').DataTable({
colReorder: true,
initComplete: function() {
resetColReorderMD()
}
})
演示 -> http://jsfiddle.net/2y4w3v6g/
在使用 ColReorder 插件时禁用列重新排序似乎毫无意义。我猜提到的 "features" 正在大量使用 ColReorder 功能,这是真正的问题,以上内容应被视为不可取的 hack。
所以我使用 jquery 数据 table 和 colReorder
来设置 table。此 table 具有一些功能,例如如何单击列 header 和 select 列以进行切换。为了使此功能正常工作,我必须启用 colReorder
。现在唯一的问题是,我所有的列都是可拖动的。我该如何解决这个问题?
这是我试过的方法
- 将
draggable
设置为 false - 将
bsort
设置为 false - 将
bsortable
设置为 false
请让我知道我做错了什么。另外,这是我的构造函数:
window.table =
$table.DataTable({
data: window.apiData['data'],
/**
dat
* Specify which columns we're going to show
*/
columns: window.columnMapping,
/**
* we want to disable showing page numbers, but still limit the number of results
*/
dom: "t",
/**
* let's disable some dynamic custom css
*/
asStripClasses: [],
/**
* let's keep the pages reasonable to prevent scrolling
*/
pageLength: 8,
/**
* this helps with hotswapping columns
*/
colReorder: true
});
谢谢!
您可以将 ColReorders 事件绑定覆盖到 <th>
元素。幸运的是,这些事件使用命名空间进行了丰富,因此可以很容易地追踪到它们,事实证明 ColReorder.mousedown
负责触发列拖动。所以你可以通过
function resetColReorderMD() {
$('.dataTable thead th').each(function() {
var md = $._data($(this)[0]).events.mousedown;
for (var i=0, l=md.length; i<l; i++) {
if (md[i].namespace == 'ColReorder') {
md[i].handler = function() {}
}
}
})
}
$('#example').DataTable({
colReorder: true,
initComplete: function() {
resetColReorderMD()
}
})
演示 -> http://jsfiddle.net/2y4w3v6g/
在使用 ColReorder 插件时禁用列重新排序似乎毫无意义。我猜提到的 "features" 正在大量使用 ColReorder 功能,这是真正的问题,以上内容应被视为不可取的 hack。