ag-grid 学习

ag-grid 学习项目要将angular从1.5升级到5,ui-grid在5中并不支持,所以为了替换ui-grid,来学习了ag-grid。简单来说,2者相差并不大,使用方式也大致雷同,这里用

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

项目要将 angular 从 1.5升级到 5,ui-grid 在 5 中并不支持,所以为了替换 ui-grid ,来学习了 ag-grid 。

简单来说,2 者相差并不大,使用方式也大致雷同,这里用 js 直观的记录一下:

<html>
<head>
    <!-- reference the ag-Grid library-->
    <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/ag-grid/10.1.0/ag-grid.js"></script>-->
    <script src="ag-grid.js"></script>
    <style>
        .orange {
            color: orange;
        }
    </style>
</head>
<body>
    <h1>Simple ag-Grid Example</h1>

    <!-- the div ag-Grid will use to render it's data -->
    <div id="myGrid" style="height: 200px;width:700px" class="ag-fresh"></div>
    
    <p>        
        <button type='button' onclick="deselectAllFnc()">clear selection</button>
        <button type='button' onclick="selectAllFnc()">select all</button>
    </p>
    <script>
        // row data ,行内数据
        var rowData = [
            {name: "Toyota", model: "Celica", price: 35000,operation: 'a', folder: true, children: [{name:'3x', model:'sss', price:37000}]},
            {name: "Ford", model: "Mondeo", price: 32000,folder: true, open: true, children: [{name:'test', model:'test', price:100}]},
            {name: "Porsche", model: "Boxter", price: 72000}
        ]
        // column definitions,表格列属性
        var columnDefs = [
            {
                headerName: 'Name',
                field: 'name',
                width: 200,
                enableRowGroup: true,
                checkboxSelection: function (params) {
                    // we put checkbox on the name if we are not doing grouping
                    return params.columnApi.getRowGroupColumns().length === 0;
                },
                headerCheckboxSelection: function (params) {
                    // we put checkbox on the name if we are not doing grouping
                    return params.columnApi.getRowGroupColumns().length === 0;
                },
                headerCheckboxSelectionFilteredOnly: true,
                cellRenderer: 'group',
                cellRendererParams: {
                    innerRenderer: function (params) { return params.data.name; },
                    suppressCount: true
                }
            },
            {headerName: "Model", field: "model"},
            {headerName: "Price", field: "price"},        
            {headerName: "Operation", field: "operation", cellRenderer: function(params) { return '<button onclick="btnClick(1);">click1</button> <button onclick="btnClick(2);">click2</button>'}}    
        ]
        // Grid Definition 
        // let the grid know which columns and what data to use
        // 表格初始化配置
        var gridOptions = {
            // PROPERTIES - object properties, myRowData and myColDefs are created somewhere in your application
            //列标题设置
            columnDefs: columnDefs,        
            //行内数据插入
            rowData: rowData,    
            animateRows: true,
            
            // PROPERTIES - simple boolean / string / number properties    
            //是否支持列宽调整
            enableColResize: true,
            //行高设置
            rowHeight: 26,
            //单行选中,"multiple" 多选(ctrl),"single" 单选
            rowSelection: 'multiple',
            // enable sorting ,是否支持排序
            enableSorting: true,
            // enable filtering ,是否可以筛选
            enableFilter: true,
            //默认筛选字段
            //quickFilterText: 's',
            //选中组可选中组下子节点
            //groupSelectsChildren: true,
            //true的话,点击行内不会进行行选择
            suppressRowClickSelection: true,
            //阻止列拖拽移动
            //suppressMovableColumns: true,
            //阻止列拖拽出表格,列移除
            suppressDragLeaveHidesColumns: true,
            //给整行加样式,
            getRowClass: function(params) { return (params.data.name === 'Ford') ? "orange" : null; },
            
            // EVENTS - add event callback handlers
            onModelUpdated: function(event) { console.log('model updated'); },
            //行内点击触发事件
            onRowClicked: function(event) { 
                //event.data 选中的行内数据,event.event 为鼠标事件,等其他。可以log自己看一下
                console.log('a row was clicked', event); 
            },
            //列宽度改变触发
            onColumnResized: function(event) { console.log('a column was resized'); },
            //表格加载完成触发
            onGridReady: function(event) { console.log('the grid is now ready'); },
            //单元格点击触发
            onCellClicked: function(event) { console.log('a cell was cilcked'); },
            //单元格双击触发
            onCellDoubleClicked: function(event) { console.log('a cell was dbcilcked'); },
            
            onCellContextMenu: function(event) { },
            onCellValueChanged: function(event) { },
            onCellFocused: function(event) { },
            onRowSelected: function(event) { },
            onSelectionChanged: function(event) { },
            onBeforeFilterChanged: function(event) { },
            onAfterFilterChanged: function(event) { },
            onFilterModified: function(event) { },
            onBeforeSortChanged: function(event) { },
            onAfterSortChanged: function(event) { },
            onVirtualRowRemoved: function(event) { },
            
            // CALLBACKS
            isScrollLag: function() { return false; },
            
            
            getNodeChildDetails: function(file) {
                if (file.folder) {
                    return {
                        group: true,
                        children: file.children,
                        expanded: file.open
                    };
                } else {
                    return null;
                }
            }            
        }
        
        //取消选中状态
        function deselectAllFnc() {
            gridOptions.api.deselectAll();
        }
        //全选
        function selectAllFnc() {
            gridOptions.api.selectAll();
        }
        
        function btnClick(value) {
            console.log(value);
        }
        
        // wait for the document to be loaded, otherwise,
        // ag-Grid will not find the div in the document.
        document.addEventListener("DOMContentLoaded", function() {
            // lookup the container we want the Grid to use
            var eGridDiv = document.querySelector('#myGrid');

            // create the grid passing in the div to use together with the columns & data we want to use
            new agGrid.Grid(eGridDiv, gridOptions);
            
            
            // create handler function,增加监听事件
            function myRowClickedHandler(event) {
                console.log('the row was clicked');
            }
            // add the handler function
            gridOptions.api.addEventListener('rowClicked', myRowClickedHandler);
        });
    </script>
</body>
</html>

 

效果图:

ag-grid 学习

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/167254.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Invalid row number (65536) outside allowable range (0..65535)

    Invalid row number (65536) outside allowable range (0..65535)《 outsideallowablerange》异常信息:   Invalidrownumber(65536)outsideallowablerange(0..65535)   今天突然接到客户通知,说使用项目中的导出功能导出的Excel文件,打开时看不到业务数据,要求立即处理一下。我打开Excel看了一下,导致的错误信息如

    2022年5月15日
  • Java中的BufferedReader与BufferedWriter简介与使用

    Java中的BufferedReader与BufferedWriter简介与使用BufferedReader和BufferedWriter是带有默认缓冲区的字符输入输出流,其效率相较于没有缓冲区要高:   1.java.io.BufferedReader和java.io.BufferedWriter类各拥有8192字符的缓冲区。当BufferedReader在读取文本文件时,会先尽量从文件中读入字符数据并置入缓冲区,而之后若使用read()方法,会先从缓冲区中进行读取。…

    2022年5月4日
  • 基于麦克风阵列的现有声源定位技术有_阵列原理

    基于麦克风阵列的现有声源定位技术有_阵列原理《基于麦克风阵列声源定位系统.doc》由会员分享,可免费在线阅读全文,更多与《基于麦克风阵列声源定位系统》相关文档资源请在帮帮文库(www.woc88.com)数亿文档库存里搜索。1、()cosiiiiettH,则有:cos()ex()()cosjiijijjiijretjkrretr()由于()()cos()cosex()jjijjijjjjiettHtHjkrr…

    2022年9月22日
  • 华为模拟器eNSP安装史上最全。。

    华为模拟器eNSP安装史上最全。。**华为模拟器基本使用**首先下载模拟工具eNSPeNSP(EnterpriseNetworkSimulationPlatform)是一款由华为提供的免费的、可扩展的、图形化操作的网络仿真工具平台,主要对企业网络路由器、交换机进行软件仿真,完美呈现真实设备实景,支持大型网络模拟,让广大用户有机会在没有真实设备的情况下能够模拟演练,学习网络技术。网站地址https://supp…

    2022年6月16日
  • VS2005 常用快捷键

    VS2005 常用快捷键

    2021年7月27日
  • matlab figure函数的用法[通俗易懂]

    matlab figure函数的用法[通俗易懂]用法1&gt;&gt;figure%创建一个新的窗口,所有参数采用默认用法2&gt;&gt;figure(s) %s为参数,s为数据时要大于0,否则报错比如下例:用法3&gt;&gt;figure(‘PropertyName’,propertyvalue,…)如下例:用法4&gt;&gt;h=figure(s)%返回该窗口的句柄,其中,s是一个整数…

    2022年7月17日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号