查找用作迭代器的单元格索引

时间:2019-02-04 11:59:01

标签: tabulator

我正在努力查找当行中的单元格已被编辑时每行的索引值。

我想使用getIndex()函数获取索引。它正在工作。如何使用行索引来遍历正在检查另一个数组中数据的检查?

我在制表器对象中尝试了以下操作:

let cashReceiptsJournalTable = new Tabulator("#CashReceiptsJournalAnswerArea", {
    data: crjAnswerData,
    layout:"fitColumns",      //fit columns to width of table
    tooltips:true,            //show tool tips on cells
    addRowPos:"top",          //when adding a new row, add it to the top of the table
    history:true,             //allow undo and redo actions on the table
    columnVertAlign:"bottom",
    columns:[                 //define the table columns
        {title:"Doc", field:"document", formatter: function(cell) {
                let cellValue = cell.getValue();

                if (cellValue !== undefined) {
                    if (cellValue === filteredCRJ[index].document) { // trying to use the index to check another array per cell
                        cell.getElement().style.backgroundColor = "#a6ff91";
                    } else {
                        cell.getElement().style.backgroundColor = "#ff8ea4";
                    }
                }
                return cellValue;
            }, width:65, editor:"input", validator: ["string"]},
        {title:"Date", field:"date", width:75, editor: "input", validator: ["integer", "min:1", "max:31"]},
        {title:"Details", field:"details", width:150, editor:"input", validator: ["string"]},
        {title:"Fol", field:"folio", width:60, editor:"input", validator: ["string"]},
        {title:"Analysis of <br>Receipts", field:"analysisOfReceipts", width:120, editor:"input", validator: ["integer", "min:1"]},
        {title:"Bank", field:"bankValue", width:80, editor:"input", validator: ["integer", "min:1"]},
        {title:"Current income", field:"currentIncome", width:140, editor:"input", validator: ["integer", "min:1"]},
        {title:"Sundry", field:"sundry",columns: [
                {title:"Account", field:"account", align: "left", editor:"input", validator: ["string"]},
                {title:"Amount", field:"amount", align:"right", editor:"input", validator: ["integer", "min:1"]}
            ],
        },
    ],
});

我无法使其与formattercellEdited一起使用。

我要做的就是在格式化程序转到已编辑的单元格的同时找到每个索引。

我希望使用console.log()将其打印出来:

console.log(cell.getIndex()) // 0 or 3 or 10 depending on where I've just input my information into the table.

我想使用索引在我的filteredCRJ数组中查找位置,以便访问该数组中嵌套对象内的document属性值。

1 个答案:

答案 0 :(得分:0)

您遇到的问题是因为 getIndex 函数位于Row Component而非Cell Component

所以您需要打电话:

var index = cell.getRow().getIndex();

仅当您在rows数据对象上设置了值时,此功能才起作用,默认情况下,这是 id 属性 {id:1,名称:“ steve”,年龄:21}

如果要查找表中的行位置,可以使用 getPosition 函数:

var position = cell.getRow().getPosition();