惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
D
DataBreaches.Net
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
M
MIT News - Artificial intelligence
美团技术团队
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Cloudflare Blog
有赞技术团队
有赞技术团队
L
LangChain Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
S
SegmentFault 最新的问题
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
B
Blog
I
InfoQ

秋码分享

我是如何解决将 c++ 编译成可以在 node.js 中使用的 *.node,中间出现的一大堆问题的(指纹浏览器基石篇) eSIM Plus 爱沙尼亚手机号彻底翻车?“永久有效”悄然变成了一年! 接码平台 SMS-Activate 余额可以转移到新平台使用,截止日期:2026年1月29日 是时候将 hugo-theme-kiwi 主题提交到 themes.gohugo.io 站点上了 Flux2 刚开源就凉了?Z-Image 本地部署狠狠打了个样 声音的未来:Chatterbox —— 用「夸张度旋钮」提升表现力的开源 TTS 向导 还以为那只是换个背景?Qwen-Image-Edit 在 ComfyUI 中能做到更离谱的事 Windows 结合最新版 ComfyUI 部署阿里最新开源的 Qwen-Image 图像大模型 从零样本到跨场景:Seed-VC语音转换技术的革命性突破 大语音模型轻量化革命:MegaTTS3 如何重新定义文本生成语音的技术边界(windows篇) 竞赛级编程大模型OlympicCoder-7B之本地部署(Windows篇) 阿里开源了端到端全模态大模型Qwen-2.5-Omini-7B之本地部署(windows篇) 语音识别之whisper本地部署(实时语音之开篇) 甭管是个人还是企业都能部署的Mistral-Small3.1,远超同级别的模型 文生音乐开源项目DiffRhythm,8G显存本地部署之Windows篇 阿里QwQ-32B本地部署指南:用Ollama轻松运行320亿参数大模型 基于Qwen2.5大模型的Spark-TTS,零样本语音克隆,CPU可运行之本地部署(Windows篇) 智谱开源了文生图CogView4-6B模型,支持中文提示词之本地部署(Windows篇) 基于歌词生成整首歌的开源AI音乐模型,支持中、英、日、韩等多种语言,本地化部署YuE(windows篇) 阿里云开源的文生视频万相 Wan2.1之本地部署Wan2.1-T2V-1.3B模型 互动式开源AI图像编辑神器,Windows11本地部署 MagicQuill 本地部署Qwen2.5-VL-7B-Instruct多模态视觉大模型(Windows篇) 保持角色一致性的绘本生成AI开源项目之Story-Adapter本地部署Windows篇 本地部署 Stable Diffusion 3.5(最新 ComfyUI记录篇) 谁说Win7安装不了Node.js最新版的呢?都2025年,还不更新系统到Win11 vs code远程调试Linux服务器上的php代码 浏览器定制 | Windows11 编译 Chromium 133.0.6885.0(截稿前Chromium最新版之编译篇[一]) 不说是彻底搞懂,至少让你不再惧怕c/c++指针,以及各种奇葩指针变种 解决windows下php8.x及以上版本,在Apache2.4中无法加载CURL扩展的问题 在 Windows8.1 下编译 Chromium (103.0.5060.68 之三)
ag-grid 右键单元格动态改变单元格样式
一个游离于山间之上的江湖漫行者。A jungle wanderer who wanders above the mountain · 2022-06-14 · via 秋码分享

在window下安装最新Go语言开发包自定义单元格单击或右键时,给单元格添加不一样的样式而苦苦搜寻,可找了好久却好像都没有呢?巧了,笔者已经实现了这一看似很简单地功能!

先来看下最终实现效果: img

你在看这篇文章的时候,那就说明你项目中已经引入了ag-grid表格库,本文是基于 vue 实现的。

<ag-grid-vue :style="{height: tableHeight,width: '100%'}" class="flex-grow-1 flex-shrink-1 ag-theme-alpine"
                                 :gridOptions="gridOptions"
                                 :columnDefs="columnDefs"
                                 :rowData="rowData"
                                 :sideBar="sideBar"
                                 :animateRows="true"
                                 :autoGroupColumnDef="autoGroupColumnDef"

                                 :defaultColDef="{
                                    sortable: true,
                                    resizable: true,
                                    filter: true,
                                    minWidth: 100,
                                 }"


                                 :groupHeaders="true"
                                 :suppressRowClickSelection="true"
                                 rowSelection="multiple"

                                 :allowContextMenuWithControlKey="true"
                                 :getContextMenuItems="getContextMenuItems"

                                 @grid-ready="onReady"
                                 @cell-clicked="onCellClicked"
                                 @cell-context-menu="onCellContextMenu"
                                 @cell-focused="onCellFocused"
                    >
                    </ag-grid-vue>

首先定义两个全局变量,注意放在 export default语句外边

let selectRow = null,selectColumn = null

export default {
    data(){
        return {
            gridOptions: null,
            gridapi: null,
            columnDefs: null,
            rowData: null,
            showGrid: false,
            sideBar: false,
            rowCount: null,
            autoGroupColumnDef: null,

        }
    },
    methods: {
        //数据是模拟   不必太在意于
         createRowData() {
                const rowData = [];

                for (let i = 0; i < 200; i++) {

                    rowData.push({
                        name: '张三'+i,
                        skills: {
                            android: Math.random() < 0.4,
                            html5: Math.random() < 0.4,
                            mac: Math.random() < 0.4,
                            windows: Math.random() < 0.4,
                            css: Math.random() < 0.4
                        },
                        dob: '张三'+i,
                        address: '张三'+i,
                        years: '2020',
                        proficiency: Math.round(Math.random() * 100),
                        country: '张三'+i,
                        continent: '张三'+i,
                        language: 'zh',
                        mobile: 134884552+'i',
                        landline: '张三'+i
                    });
                }

                this.rowData = rowData;
            },
            createColumnDefs() {
                this.columnDefs = [
                    {
                        headerName: '#', minWidth: 60, width: 60, checkboxSelection: true, sortable: false,
                        suppressMenu: true, pinned: true
                    },
                    {
                        headerName: 'Employee',
                        children: [
                            {
                                headerName: "Name", field: "name", editable: true,
                                width: 150, pinned: true,
                            },
                            {
                                headerName: "Country", field: "country", width: 150,
                            },
                            {
                                headerName: "DOB",
                                field: "dob",
                                width: 120,
                                pinned: true,

                                filter: 'agDateColumnFilter',
                                columnGroupShow: 'open'
                            }
                        ]
                    },
                    {
                        headerName: 'IT Skills',
                        children: [
                            {
                                headerName: "Skills",
                                width: 125,
                                sortable: false,
                            },
                            {
                                headerName: "Proficiency",
                                field: "proficiency",
                                width: 120,
                            },
                        ]
                    },
                    {
                        headerName: 'Contact',
                        children: [
                            {
                                headerName: "Mobile",
                                field: "mobile",
                                width: 150,
                                filter: 'text'
                            },
                            {
                                headerName: "Land-line",
                                field: "landline",
                                width: 150,
                                filter: 'text'
                            },
                            {headerName: "Address", field: "address", width: 500, filter: 'text'}
                        ]
                    }
                ];
            },
        onReady(params) {
            console.log('onReady');

            this.gridapi = params.api;
            this.calculateRowCount();

            this.gridapi.sizeColumnsToFit();
        },

        //单元格点击事件
        onCellClicked(event) {
            //selectRow = event.data
            //selectColumn = event.colDef

        },

        /**
        * 右键弹出菜单
        */
        onCellContextMenu(event) {

            let headerDom = document.querySelectorAll('.ag-cell')
            for (const n of headerDom) {
                n.style.backgroundColor = '#fff'
                n.style.color = '#000'
            }

            var column = event.colDef.field;


            if (event.data === selectRow && event.colDef === selectColumn) {
                //return 'col-orange'
                event.colDef.cellStyle = { 'background-color': '#f60', 'color': '#fff' };
            }

            this.gridapi.refreshCells({
                force: true,
                columns: [column],
                rowNodes: [event.node]
            });


    },
        //单元获得焦点
        onCellFocused(event) {
            let rowData = this.gridapi.getRowNode(event.rowIndex)
            selectRow = rowData.data
            selectColumn = event.column.colDef
        },
   },
    beforeMount() {
        this.gridOptions = {};
        this.gridOptions.components = {agDateInput: DateComponent};
        this.createRowData();
        this.createColumnDefs();
        this.showGrid = true;
    },
}