简体   繁体   English

Handsontable:如何在渲染功能中更改单元格值

[英]Handsontable : how to change cell value in render function

I have similar code: 我有类似的代码:

<script>
$(document).ready(function () {
    var data = @Html.Raw(ViewBag.Data);

function sumPreviousValues(instance, td, row, col, prop, value, cellProperties) {
  Handsontable.renderers.TextRenderer.apply(this, arguments);
    td.val = 'SUM SEVERAL PREVIOUS CELLS';
}

     container = document.getElementById('example1'),
      settings1 = {
        data: data,
        colHeaders: @Html.Raw(ViewBag.TableHeader),
        cells: function (row, col, prop) {
            var cellProperties = {};

            if (col == 16) {
                cellProperties.renderer = sumPreviousValues;
            }
    return cellProperties;
        }
      },

    hot = new Handsontable(container,settings1);
    hot.render();

The key is to modify the function sumPreviousValues() 关键是修改函数sumPreviousValues()

But I dont know how to access the td value ? 但我不知道如何访问td值? and if it is possible to access other cells' value like td[index] . 如果可以像td[index]那样访问其他单元格的值。 Any idea? 任何想法? I didn't find options in documentation. 我没有在文档中找到选项。

Thank you 谢谢

I think I understand what you want to do and here is a simple solution: 我想我明白你想做什么,这是一个简单的解决方案:

From inside the custom renderer, you can call: 从自定义渲染器内部,您可以调用:

instance.getDataAtCell(row, col);

This will give you the data (value) of the cell at row,col . 这将为您提供row,col的单元格的数据(值)。 Hope that helps :) 希望有帮助:)

Also, to access the value at the current td, you just use the value variable :P Look at the function definition. 另外,要访问当前td的值,只需使用value变量:P查看函数定义。 You are literally passing it in and is available to you. 你实际上是在传递它并且可以使用。

To qualify this question, can you inspect the td param being passed into sumPreviousValues() . 要限定此问题,您可以检查传递给sumPreviousValues()td参数。 It would help to understand what this is, I would assume it's a HTML DOM node. 这将有助于理解这是什么,我认为它是一个HTML DOM节点。 If so, you could adjust it's value using td.innerHTML 如果是这样,你可以使用td.innerHTML调整它的值

More information on this can be found here: http://www.w3schools.com/jsref/prop_html_innerhtml.asp 有关这方面的更多信息,请访问: http//www.w3schools.com/jsref/prop_html_innerhtml.asp

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

相关问题 如果前一个单元格具有值 HandsOnTable,如何将单元格更改为非活动状态 - How create change cell to inactive if previous cell has value HandsOnTable 使用handsontable获取单元格的值-错误:方法不是函数 - Get the value of a cell with handsontable - Error : method is not a function 如何使jQuery .change()引用Handsontable上的单元格? - How to get jQuery .change() to reference cell on a Handsontable? 如何在单元格中下拉值的变化中仅在几个列上加载数据? - How to load data only on few columns in handsontable on change in the value of a dropdown in a cell? 使用或不使用 setDataAtCell/getDataAtCell handsontable 更改单元格值 afterChange - change cell value afterChange with or without setDataAtCell/getDataAtCell handsontable 如何根据Handsontable中另一个单元格的条件/值将样式应用于单元格 - How to apply style to a cell based on the condition/value of another cell in Handsontable 如何根据Handsontable中的表格单元格值设置表格单元格外观 - How to set table cell appearance depending on table cell value in Handsontable HandsOnTable:动态更改单元格边框 - HandsOnTable: Change cell borders dynamically 如何更改 Handsontable 中已更改单元格的颜色? - How can I change the color of a changed cell in Handsontable? Handsontable-隐藏特定行(按单元格值) - Handsontable - hide specific row ( by cell value)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM