简体   繁体   English

tabulator.js - scrollToRow() 在树上不起作用?

[英]tabulator.js - scrollToRow() doesn't work on tree?

I've got a Tabulator.js table.我有一个 Tabulator.js 表。 This table is a treeview used dataTree option.此表是 treeview 使用的 dataTree 选项。 Rows have a unique id in column 'id'.行在“id”列中具有唯一的 id。

scrollToRow() function throws the following error: scrollToRow() function 抛出以下错误:

Unhandled rejection Scroll Error - No matching row found未处理的拒绝滚动错误 - 找不到匹配的行

table = new Tabulator("#cutover_plan_table_container", {
            height:"500px",
            headerSort: false,
            data:hierarchical_cutover_obj,
            dataTree:true,
            dataTreeStartExpanded:true,
            dataTreeElementColumn:"name",
            dataTreeChildField:"outlineChildren",
            dataTreeBranchElement:false,
            dataTreeChildIndent:17,
            scrollToRowPosition: "center",
            index:"id", 
            virtualDom: true,
            virtualDomBuffer : true,
    
            columns:[
                {title:"", field:"id", align:"center",cssClass:"cutover_column_id"},
                {title:"UID", field:"uid"},
                {title:"Name", field:"name", responsive:0},
                {title:"Predecessor", field: "predecessor", width:150,formatter:function(cell, formatterParams, onRendered){
                    return '<a href="javascript:goToTableRow(' + cell.getValue() + ');">' + cell.getValue()+ '</a>, ';
                }}
            ]
    }); 
    
    
function goToTableRow(targetRow){
        table.scrollToRow(targetRow, "center", true);
} 

If I click Predecessor cell value then I get an Unhandled rejection Scroll Error - No matching row found error on console.如果单击Predecessor单元格值,则会收到未处理的拒绝滚动错误 - 控制台上未找到匹配行错误。 If it isn't a tree (dataTree: false ) then scroll is working like a charm.如果它不是一棵树(dataTree: false ),那么滚动就像一个魅力。

First off, and slightly unrelated to your original question, that is a really bad approach to triggering a scroll, you can just use the cellClick callback and then you dont need a custom formatter or function:首先,与您的原始问题稍有无关,这是触发滚动的一种非常糟糕的方法,您可以使用cellClick回调,然后您不需要自定义格式化程序或 function:

{title:"Predecessor", field: "predecessor", width:150, cellClick:function(e, cell){
    table.scrollToRow(cell.getValue(), "center", true);
}}

Secondly, the issue is arising because you cannot target child rows by id, the lookup only works on top level data.其次,问题的出现是因为您无法按 id 定位子行,查找仅适用于顶级数据。

If all you are doing is trying to scroll to the parent row, then you can use the getTreeParent function on the row component and call the scrollTo function directly on it.如果您所做的只是尝试滚动到父行,那么您可以在行组件上使用getTreeParent function 并直接在其上调用scrollTo function。

{title:"Predecessor", field: "predecessor", width:150, cellClick:function(e, cell){
    var parent = cell.getTreeParent();

    if(parent){
        parent.scrollTo();
    }
}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM