十一月上旬更新速递丨 数据与 AI 技术深耕、场景应用拓展与开发进阶实战

秋意正浓时,智能征程不止步!十一月上旬欢度14周年,聚焦数据与AI领域的知识深化、场景化应用落地、技术开发进阶,从理论到实战的全链路能力提升!

一、14周年活动

《14周年·探索乐章 | 寻藏宝图,挖掘社区金矿(已更新1-9关卡)开启一场知识寻宝探险之旅,重温与思迈特并肩成长的温暖时光!

《14周年·温情乐章|写下专属祝福,传递温暖情谊为思迈特14周年注入一份温度,也为这份同行之谊添上一抹亮色!

《14周年·荣誉乐章 | 星光致敬,表彰贡献榜样→回馈大家对社区生态的倾心建设,感谢每一位共建者的热忱与坚守!

二、场景应用

《构建“战略-业务-数据”三层指标体系(体系篇)》→“战略-业务-数据”三层指标体系是AIChat听懂的坚实的底层支撑。

三、术经验分享

《【专家分享】用Smartbi快速搞定数据刷新,老板看了都说好!》→掌握了数据刷新“提速”秘籍:告别滞后,让数据“实时在线”!

《【专家分享】数据排序的“权力游戏”:优先级规则决定谁先谁后》→提供了数据排序指南:破解多指令冲突,明确 “谁先生效”!

四、二次开发视频

扩展包开发前端改造了解前端改造的基本方法与实现流程、如何在Smartbi扩展包中修改CSS样式、扩展JS组件。

、任务持续上线

《【场景实战】数据驱动决策全流程实战:dws层数据处理》→深入数据决策,提升数据整合与维度设计能力,挑战成功即可获得麦豆奖励!

《【AIChat入门闯关计划】-随机掉落小测试》→快速检验AIChat知识漏洞,巩固核心概念。接受挑战即可获得麦豆奖励。

为进一步提升认证服务的质量与体验,我们对认证业务进行全面优化升级。更多详情请看Smartbi认证考试优化升级公告

麦粉社区
>
帖子详情

填报表批量删除的实现

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

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

发表于 2025-7-1 11:35:32
本帖最后由 周伟斌 于 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(); //刷新报表
    }
}


 


 

打赏人数1麦豆 +40 收起 理由
Smartbi社区管理员 + 40 太棒了,给你32个赞,么么哒

查看全部打赏

  •   Smartbi社区管理员
    这也太棒了吧!还有详细的流程截图,流程清晰明了,还有重点说明,太细心了,看完感觉我也可以,感动了感动了,必须给你打个赏!
    2025-7-2 11:08| 回复

回复

使用道具 1 举报

发表于 2025-7-1 19:30:17
赞赞赞,有时间必须得试一下,强强强
回复

使用道具 举报

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

本版积分规则

3回帖数 0关注人数 845浏览人数
最后回复于:2025-7-1 19:30
快速回复 返回顶部 返回列表