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 学习

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • CICD介绍「建议收藏」

    CICD介绍「建议收藏」CICD一概要CICD的采用改变了开发人员和测试人员如何发布软件最初是瀑布模型,后来是敏捷开发,现在是DevOps,这是现代开发人员构建出色的产品的技术路线。随着DevOps的兴起,出现了持续集成(ContinuousIntegration)、持续交付(ContinuousDelivery)、持续部署(ContinuousDeployment)的新方法。传统的软件开发和…

  • python不换行输出

    python不换行输出#!/usr/bin/envpython#-*-coding=utf-8-*-'''Createdon2018年6月24日@author:sairo&#3

  • 使用多重循环打印平行四边形「建议收藏」

    packagecom.qfedu.test1;/*** 使用多重循环打印平行四边形* 当我们打印三角形的时候:* 1.观察第一行符号的个数,第一行符号的个数决定了循环计数器的初始值* 2.观察形状符号的个数是越来越多的话就++越来越少就–* 3.当计数器变化为++的时候判断条件一定要小于或者小于等于某个值相当于设定一个上限* 4.当计数器变化为–的时候判断条件一定要大于或者大于等于某个值相当于设定一个下限*/publicclassT

  • Django(22)Django执行SQL语句

    Django(22)Django执行SQL语句前言Django在查询数据时,大多数查询都能使用ORM提供的API方法,但对于一些复杂的查询可能难以使用ORM的API方法实现,因此Django引入了SQL语句的执行方法,有以下三种执行方式ext

  • 易语言注入 c dll,易语言DLL注入模块简单型

    易语言注入 c dll,易语言DLL注入模块简单型易语言DLL注入模块简单型系统结构:注入DLL,卸载DLL,提取错误标题,提取错误信息,提取错误代码,UnHookDLL,OpenProcess,VirtualAllocEx,CloseHandle,WriteProcessMemory,VirtualFreeEx,GetModuleHandle,GetProcAddress,CreateRemoteThread,WaitForSingleObje…

  • jvm的垃圾回收算法_jvm默认的垃圾回收器

    jvm的垃圾回收算法_jvm默认的垃圾回收器前言相比C语言,JVM虚拟机一个优势体现在对对象的垃圾回收上,JVM有一套完整的垃圾回收算法,可以对程序运行时产生的垃圾对象进行及时的回收,以便释放JVM相应区域的内存空间,确保程序稳定高效的运行,但在真正了解垃圾回收算法之前,有必要对JVM的对象的引用做一个简单的铺垫JVM对象可达性分析算法Java虚拟机中的垃圾回收器采用可达性分析来探索所有存活的对象扫描堆中的对象,看是否能够沿着GCRoot对象为起点的引用链找到该对象,找不到表示可以被回收想象一下,对象在什么情况下会被认为是垃圾对象呢?

    2022年10月25日

发表回复

您的电子邮箱地址不会被公开。

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