行式填报表在删除数据时弹出提示

 

润乾 v4
在润乾报表中,如果将报表设置成行式填报表,那么我们可以对数据进行插入,添加,删除等操作。点击“删除”按钮的时候,会直接将数据删除掉。有时候可能会不小心点到了“删除”按钮,将不想删除的数据给删除掉了。这种情况会让人很苦恼,在操作的时候也没那么随心所欲。

为了避免这种情况,我们需要在删除数据的时候,弹出一个对话框进行提示:是否确定删除该数据?

下面我们一起来看一下,如何实现这种效果。

在一张填报表做好之后,修改一下发布报表的 JSP。在其中添加一个自定义按钮“自写行删除”,如下图

 

图 1

这个按钮调用的是 _deleteRow123(report1) 这个 js 函数。

_deleteRow123(report1) 方法如下:

function _deleteRow123(table) {

       if(confirm(”确定删除吗?“)==true){

              if(table.currCell == null) {

              alert(__AAA);

              return;

       }

       var row = table.currCell.parentElement;

       if(!row.isDetail) {

              alert(__BBB);

              return;

       }

       var oldCellIndex = table.currCell.colNo;

       var index = row.rowIndex;

       var currCellRowIndex = index;

       while(!row.isFirst) {

              index–;

              row = table.rows[index];

       }

       findRowNoInGroup(table, row);

       var deltaIndex = currCellRowIndex – index;

       var drows = parseInt(row.drows);

       var srcCell = row.cells[0].sc;

       var firstIndex = index, tmpIndex = index;

       var details = 1;

       while(true) {  // 查找本扩展区的第一条记录的首行

              if(tmpIndex == 0) break;

              tmpIndex–;

              var r = table.rows[tmpIndex];

              if(!r.isDetail) break;

              if(r.isFirst) {

                     if(r.cells[0].sc == srcCell ) {

                            firstIndex = tmpIndex;

                            if(!r.deleted) details++;

                     }

                     else break;

              }

       }

       var lastIndex = index;

       tmpIndex = index;

       while(true) {  // 查找本扩展区的最后一条记录的首行

              tmpIndex++;

              var r = table.rows[tmpIndex];

              if(r == null || !r.isDetail) break;

              if(r.isFirst) {

                     if(r.cells[0].sc == srcCell ) {

                            lastIndex = tmpIndex;

                            if(!r.deleted) details++;

                     }

                     else break;

              }

       }

       if(details == 1) {  // 最后一条明细了,需要先复制一个空明细

              table.currEditor = null;

              _copyRows(table, row, index);

              index += drows;

       }

       for(var i = 0; i < drows; i++) {

              row = table.rows[index + i];

              for(var j = 0; j < row.cells.length; j++) {

                     row.cells[j].style.display = “none”;

              }

              row.deleted = true;

              row.style.display = “none”;

       }

       if(details > 1) {

              var currRow = null;

              var n = index;

              while(true) {  // 往后搜索新的当前行

                     index += drows;

                     var r = table.rows[index];

                     if(r == null || !r.isDetail) break;

                     if(r.style.display == “none”) continue;

                     if(r.cells[0].sc != srcCell ) break;

                     currRow = r;

                     break;

              }

              if(currRow == null) { // 往前搜索新的当前行

                     index = n;

                     while(true) {

                            index -= drows;

                            var r = table.rows[index];

                            if(r == null || !r.isDetail) break;

                            if(r.style.display == “none”) continue;

                            if(r.cells[0].sc != srcCell ) break;

                            currRow = r;

                            break;

                     }

              }

              currRow = table.rows[currRow.rowIndex + deltaIndex];

              var currCell = null;

              for(var k = 0; k < currRow.cells.length; k++) {

                     var c = currRow.cells[k];

                     if(c.colNo == oldCellIndex) {

                            currCell = c;

                            break;

                     }

              }

              if(currCell != null) {

                     table.currEditor = null;

                     _bindingEditor(currCell);

              }

       }

       _calcTbl(table, row.cells[0] );  // 删除一行时,重新计算相关组的统计值

       _calcRowNoInGroup(table, row);

       }

       else{

              return false;

       }

}

如此设置之后,当点击“自写行删除”按钮时,会弹出一个对话框,询问是否确实要删除该数据,点击“确认”则删除该数据,点击“取消”则不删除该数据。如下图