[英]Datatables - horizontal scrolling for only certain columns
Datatables中的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'})
})
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.