[英]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.