数据表中的scrollX选项允许用户水平滚动网格 - 但是,在我的表中,我需要将前两列保持在适当的位置,但允许接下来的x列水平滚动。我没有看到任何关于如何执行此操作的好示例。
示例: https://datatables.net/examples/basic_init/scroll_x.html
最佳答案
您可以通过根据 scrollLeft
值更改每个单元格的相对位置来实现此目的。
$('.dataTables_scrollBody').scroll(function (){
var cols = 2 // how many columns should be fixed
var container = $(this)
var offset = container.scrollLeft()
container.add(container.prev()).find('tr').each(function (index,row){ // .add(container.prev()) to include the header
$(row).find('td, th').each(function (index,cell){
if(index>=cols) return
$(cell).css({position:'relative',left:offset+'px'})
})
})
})
关于javascript - 数据表 - 仅针对某些列进行水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48795732/