Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Handsontable:如何对行进行求和?_Javascript_Jquery_Html_Handsontable - Fatal编程技术网

Javascript Handsontable:如何对行进行求和?

Javascript Handsontable:如何对行进行求和?,javascript,jquery,html,handsontable,Javascript,Jquery,Html,Handsontable,我从数据库动态获取列,所以我不知道有多少列,但行数是固定的 这是一个例子 var数据=[ [''‘特斯拉’、‘日产’、‘丰田’、‘本田’, [‘汽车数量’,-5,5,12,13], [《汽车价格》,10,-11,14,13], [tax',2,15,-12,30], [‘所有汽车的总价’,10、-11、14、13], [“税前价格”,2,15,-12,30], [“税后价格”,2,15,-12,30] ], 集装箱, hot1; 函数firstRowRenderer(实例、td、行、列、属性、

我从数据库动态获取列,所以我不知道有多少列,但行数是固定的

这是一个例子

var数据=[
[''‘特斯拉’、‘日产’、‘丰田’、‘本田’,
[‘汽车数量’,-5,5,12,13],
[《汽车价格》,10,-11,14,13],
[tax',2,15,-12,30],
[‘所有汽车的总价’,10、-11、14、13],
[“税前价格”,2,15,-12,30],
[“税后价格”,2,15,-12,30]
],
集装箱,
hot1;
函数firstRowRenderer(实例、td、行、列、属性、值、cellProperties){
Handsontable.renderers.textrender.apply(这是参数);
td.style.fontwweight='bold';
td.style.color='绿色';
td.style.background='#CEC';
}
函数negativeValueRenderer(实例、td、行、列、属性、值、cellProperties){
Handsontable.renderers.textrender.apply(这是参数);
//如果行包含负数
if(parseInt(值,10)<0){
//添加“负”类
td.className='make me red';
}
如果(!value | | value==''){
td.style.background='EEE';
}
否则{
如果(值==‘日产’){
td.style.fontStyle='italic';
}
td.style.background='';
}
}
//将函数映射到查找字符串
Handsontable.renders.registerRenderer('negativeValueRenderer',negativeValueRenderer);
container=document.getElementById('example1');
hot1=新的可手持设备(容器、{
数据:数据,
许可证密钥:“非商业和评估”,
余选:函数(行、列、行2、列2){
var meta=this.getCellMeta(第2行,第2列);
if(meta.readOnly){
this.updateSettings({fillHandle:false});
}
否则{
this.updateSettings({fillHandle:true});
}
},
单元格:功能(行、列){
var cellProperties={};
var data=this.instance.getData();
如果(行===0 | |数据[行]和数据[行][col]==='readOnly'){
cellProperties.readOnly=true;//如果单元格是第一行或文本为“readOnly”,则将其设为只读
}
如果(行===0){
cellProperties.renderer=firstRowRenderer;//直接使用函数
}
否则{
cellProperties.renderer=“negativeValueRenderer”;//使用查找映射
}
归还财产;
}
});
。把我弄红{
颜色:#f00;
}

您可以使用Hansontable列摘要,不需要使用setDataAtCell/setDataAtRow方法

columnsumry:function(){
//hotInstance(获取总行和总列)
让sumRow=this.hot.countRows()-1;
设colSummaryArr=[];
if(this.hot.countCols()>0){
//金额为第3列之后的金额
for(设i=3;i},
我不明白你的问题。你能再详细一点吗?是否要对每行的单元格进行求和(总计列)?使用
setDataAtCell
有什么问题?而且,您的JSFIDLE链接似乎已经死了