Handsontable:如何在渲染函数中更改单元格值 [英] Handsontable : how to change cell value in render function
问题描述
我有类似的代码:
<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();
关键是修改功能sumPreviousValues()
但是我不知道如何访问td
值?以及是否可以访问其他单元格的值,例如td[index]
.
任何的想法?我在文档中找不到选项.
But I dont know how to access the td
value ? and if it is possible to access other cells' value like td[index]
.
Any idea? I didn't find options in documentation.
谢谢
推荐答案
我想我知道您想要做什么,这是一个简单的解决方案:
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);
这将为您提供row,col
处单元格的数据(值).希望能有所帮助:)
This will give you the data (value) of the cell at row,col
. Hope that helps :)
此外,要访问当前td的值,您只需使用value
变量:P查看函数定义.您实际上是在传递它,并且可以使用它.
Also, to access the value at the current td, you just use the value
variable :P Look at the function definition. You are literally passing it in and is available to you.
这篇关于Handsontable:如何在渲染函数中更改单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!