六月下旬全新资源上线!丨 解锁高效能实战方案

更新亮点:本次新增5大专题9项资源,点击标题5分钟极速了解!参与互动赢取麦豆,解锁更多内容)

一、实战技巧分享

即席/透视的逆袭之路:从卡顿到秒出→ 性能优化实战,实现报表秒级响应!

体验中心焕新一“夏”,全新导览页及新DEMO上线!→ 抢先体验夏季更新DEMO!

速看!明细/汇总/交叉表的实现秘籍→ 高效构建复杂报表指南

二、开发技能突破

视频课《仪表盘图片鼠标提示几行代码,让你的仪表盘“会说话”!

视频课《仪表盘宏开发技巧→ 解锁宏开发技巧和注意事项

三、直播上线

直播《交互式仪表盘最佳实践解锁可视化大屏最佳实践技巧

四、AI每日一学

人工智能三驾马车:算法、算力与数据→ 深度解析AI核心支柱

通俗的讲一下神经网络模型的基本组成、工作原理、工作类型和生活应用场景→ 从基础到场景实战

五、资源上新

插件《安全检测→ 一键加固系统安全防护

麦粉社区
>
帖子详情

填报表批量删除的实现

干货分享 发表于 10 小时前
发表于 10 小时前
本帖最后由 周伟斌 于 2025-7-1 11:37 编辑

有没有人对填报表批量删除感兴趣的

发表于 10 小时前
本帖最后由 周伟斌 于 2025-7-1 11:36 编辑

实现方式如下:


 


1、添加用于操作的列:


PS:历史填报表增加列时,需调整回写规则



2、设置选择框左父格为ID的单元格


PS:避免合并单元格



3、全局宏设置


也可参照全局宏代码编写私有宏


function main(spreadsheetReport, isAjaxRefreshCallback) {
    //console.log(spreadsheetReport, isAjaxRefreshCallback);
    var allCheckBoxCell; //全选单元格
    var detailCheckbocCell; //明细选择单元格
    var idCheckbocCell; //明细ID单元格
    var dataSource; //数据源
    var tablename; //表名
    switch (spreadsheetReport.reportId) {
        case 'I2c91808c0192ea75ea751718019323a528e06a7a':
            allCheckBoxCell = "U2";
            detailCheckbocCell = "U3";
            idCheckbocCell = "B3";
            dataSource = "DS.StrongBiPublic";
            tablename = "labor_cost_adjust_import";
            break;
        default:
            return;
    }
    render(spreadsheetReport, allCheckBoxCell, detailCheckbocCell, idCheckbocCell, dataSource, tablename);
}

/**
* 工具栏添加批量删除按钮
* @param spreadsheetReport 填报表对象
* @param allCheckBoxCell 全选单元格
* @param detailCheckbocCell 明细选择单元格
* @param idCheckbocCell 明细ID单元格
* @param dataSource 数据源
* @param tablename 表名
* @returns
*/
function render(spreadsheetReport, allCheckBoxCell, detailCheckbocCell, idCheckbocCell, dataSource, tablename) {
    if (!spreadsheetReport._batchDeleteBtn) {
        var input = document.createElement("button");
        input.className = "button-buttonbar icon-queryview-toolbar-button-normal";
        input.innerText = "批量删除";
        input.style.width = "70px";
        input.style.height = "25px";
        input.style.verticalAlign = 'top';
        input.style.marginLeft = "12px";
        var target = spreadsheetReport.elem_space2.parentNode.nextSibling;
        var newBtn = target.parentNode.insertBefore(input, target);

        spreadsheetReport.addListener(newBtn, "click", function() {
            doNewButtonClick(spreadsheetReport, dataSource, tablename);
        }, spreadsheetReport);

        spreadsheetReport._batchDeleteBtn = newBtn;
    }

    try {

        //增加全选复选框
        var allCheckBox_td = spreadsheetReport.getCell(allCheckBoxCell); //获取全选单元格
        if (allCheckBox_td) {
            var checkboxElement = allCheckBox_td.querySelector('input[type="checkbox"]');

            if (checkboxElement) {
                //console.log('复选框存在1');
                return;
            }
            var _allChceckBtn = document.createElement('input');
            _allChceckBtn.id = 'allCheckBox';
            _allChceckBtn.type = 'checkbox';

            //监听处理全选
            _allChceckBtn.addEventListener('change', function() {
                allCheckChange(spreadsheetReport);
            });

            allCheckBox_td.insertBefore(_allChceckBtn, allCheckBox_td.firstChild);
            spreadsheetReport._allChceckBtn = _allChceckBtn;
        }

        var checkboxCells = spreadsheetReport.getExpandedPositions(detailCheckbocCell); //获checkbox所有单元格
        var idCells = spreadsheetReport.getExpandedPositions(idCheckbocCell); //获ID所有单元格
        spreadsheetReport._allChceckBtns = [];
        for (var i = 0; i < checkboxCells.length; i++) {
            var checkbox_td = spreadsheetReport.getCell(checkboxCells);
            var id_td = spreadsheetReport.getCell(idCells);
            if (checkbox_td && id_td) {
                var id = id_td.innerText; //获取id

                var checkbox = document.createElement('input');
                checkbox.type = 'checkbox';
                checkbox.setAttribute('data_id', id);

                // 将复选框添加到单元格中
                checkbox_td.appendChild(checkbox);
                spreadsheetReport._allChceckBtns.push(checkbox);
            }
        }
    } catch (error) {
        //新增行会报一个Cannot read properties of undefined (reading 'toUpperCase')忽略处理
        alert('批量删除功能异常请联系管理员');
        console.error('发生异常:', error);
    }
}

function allCheckChange(spreadsheetReport) {
    if (spreadsheetReport._allChceckBtns) {
        spreadsheetReport._allChceckBtns.forEach(function(checkbox) {
            checkbox.checked = spreadsheetReport._allChceckBtn.checked;
        });
    }
}

function doNewButtonClick(spreadsheetReport, dataSource, tablename) {
    var del_ids = [];
    spreadsheetReport._allChceckBtns.forEach(function(checkbox) {
        if (checkbox.checked) {
            var id = checkbox.getAttribute('data_id');
            del_ids.push(id);
        }
    });
    if (del_ids.length == 0) {
        alert("请选择要删除的数据!");
        return;
    }
    var modalWindow = jsloader.resolve("freequery.common.modalWindow");
    var flag = confirm("确认删除以下数据吗?\r\n" + JSON.stringify(del_ids));
    if (flag) {
        // 将数组中的字符串格式化为 'x' 格式
        var formattedStrings = del_ids.map(function(str) {
            return "'" + str + "'";
        });

        // 使用逗号连接格式化后的字符串
        var result = formattedStrings.join(',');

        var util = jsloader.resolve("freequery.common.util");
        var sql = "delete from " + tablename + " where id in (" + result + ")";
        var ret = util.remoteInvoke("DataSourceService", "executeUpdate", [dataSource, sql]); //执行删除数据的sql
        if (ret.succeeded) {
            alert("删除成功");
        } else {
            alert("删除失败");
        }
        spreadsheetReport.doRefresh(); //刷新报表
    }
}


 


 

回复

使用道具 举报

发表于 2 小时前
赞赞赞,有时间必须得试一下,强强强
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

2回帖数 0关注人数 51浏览人数
最后回复于:2 小时前
快速回复 返回顶部 返回列表