行式报表插入数据时复制行信息

来源:互联网 发布:荆鹏软件 编辑:程序博客网 时间:2024/06/05 07:52

行式填报报表在与普通填报表最大的区别就是在填报的时候可以插入记录,当点击插入按钮的时候,可以通过流水号给新增数据赋默认值,也可以给报表所有的列都赋默认值,但是如果遇到比较复杂的需求,比如第一列自增,其他列取上一行的记录,这时候用流水号就需要写复杂的js了,而且效率也不理想,下面提供一个简单的方来解决上述需求。

思路,重写insertRow()这个js,然后在页面调用这个新的js。进行插入。
function _insertRow(table){
if(confirm(”确定插入?”)==true){
if( !_submitEditor( table ) ) return;
if( table.currCell == null ) {
alert( __UU );
return;
}
var row = table.currCell.parentElement;
if( !row.isDetail ) {
alert( __VV );
return;
}
var index = row.rowIndex;
while( !row.isFirst ) {
index–;
row = table.rows[ index ];
}
_copyRows( table, row, index );
_calcRowNoInGroup( table, row );
}
else{
return false;
}
}

从上面的js中的_copyRows( table, row, index )这个函数实现的是复制行的功能,下面看一下这个js
function _copyRows( table, baseRow, index ) {
findRowNoInGroup( table, baseRow );
var drows = parseInt( baseRow.drows );
var baseRows = new Array( drows );
baseRows[0] = baseRow;
for( var i = 1; i < drows; i++ ) {
baseRows[i] = table.rows[ baseRow.rowIndex + i ];
}
var firstIndex;
for( var i = 0; i < drows; i++ ) {
var rowIndex = index;
if( index > -1 ) rowIndex = index + i;
var m = _copyARow( table, baseRows[i], rowIndex );
if( i == 0 ) firstIndex = m;
table.nextRowNo++;
}
return firstIndex;
}

数据的复制都是在_copyARow( table, baseRows[i], rowIndex )这个js中实现的,所以报表复制上一行数据并且第一列流水号增加的功能就要在这个js中实现。
function _copyARow111( table, baseRow, index ) {
var newrow = table.insertRow( index );
var newRowStyle = baseRow.cloneNode( true );
newRowStyle.id = table.id + “_row” + table.nextRowNo;
newRowStyle.status = “2″;
newrow.replaceNode( newRowStyle );
var currCell = null;
for( var i = 0; i < baseRow.cells.length; i++ ) {
var newColStyle = newRowStyle.cells[i];
if( table.currCell == baseRow.cells[i] ) currCell = newColStyle;
if( newColStyle.oldBkcolor != null ) newColStyle.style.backgroundColor = newColStyle.oldBkcolor;
if( newColStyle.flow ) {
if( newColStyle.flow.indexOf( “rowNoInGroup” ) < 0 ) {
li_currTbl = table;
li_currCell = newColStyle;
var flow = eval( newColStyle.flow ) + “”;
if(flow!=null&&flow!=””){
newColStyle.innerText = flow;
newColStyle.value = flow;
}
}
}
else {
var es = newColStyle.editStyle;
}
var id = newColStyle.id;
var pos = 0;
for( var k = id.length – 1; k >= 0; k– ) {
var s = id.substring( k );
if( isNaN( s ) ) {
pos = k + 1;
break;
}
}
id = id.substring( 0, pos ) + table.nextRowNo;
newColStyle.id = id;
if( newColStyle.filterCells != null ) {
var fcs = newColStyle.filterCells.split( “,” );
var s2 = “”;
for( var m = 0; m < fcs.length; m++ ) {
var fc = fcs[m];
var spos = 0;
for( var k = fc.length – 1; k >= 0; k– ) {
var s = fc.substring( k );
if( isNaN( s ) ) {
spos = k + 1;
break;
}
}
fc = fc.substring( 0, spos ) + table.nextRowNo
if( s2.length > 0 ) s2 += “,”;
s2 += fc;
}
newColStyle.filterCells = s2;
}
}
if( currCell != null && !table.isImport ) _bindingEditor( currCell );
return newRowStyle.rowIndex;
}

这样就能实现插入复制行,当然报表自增的字段仍然需要设置流水号,而且流水号取值要用自增1的函数例如:groupMaxNumber();这些js也要重命名一下,用以区别报表自带的同名js。