React 表格组件 GridManager

GridManager React

> 基于 React 的 GridManager 封装, 用于便捷的在 React 中使用GridManager. 除过React特性外,其它API与GridManager API相同。

image

实现功能

  • 宽度调整: 表格的列宽度可进行拖拽式调整
  • 位置更换: 表格的列位置进行拖拽式调整
  • 配置列: 可通过配置对列进行显示隐藏转换
  • 表头吸顶: 在表存在可视区域的情况下,表头将一直存在于顶部
  • 排序: 表格单项排序或组合排序
  • 分页: 表格ajax分页,包含选择每页显示总条数和跳转至指定页功能
  • 用户偏好记忆: 记住用户行为,含用户调整的列宽、列顺序、列可视状态及每页显示条数
  • 序号: 自动生成序号列
  • 全选: 自动生成全选列
  • 导出: 当前页数据下载,和仅针对已选中的表格下载
  • 右键菜单: 常用功能在菜单中可进行快捷操作
  • 过滤: 通过对列进行过滤达到快速搜索效果

API

> 该文档为原生GridManager的文档,react版本除了在columnData.text columnData.template topFullColumn.template中可以使用react模版外,其它使用方式相同。

Demo

> 该示例为原生GridManager的示例,react版本除了在columnData.text columnData.template topFullColumn.template中可以使用react模版外,其它使用方式相同。

Core code

开发环境

ES2015 + webpack + React + GridManager

项目中引用

  • es2015引入方式

    import ReactGridManager, {$gridManager} from 'gridmanager-react'; import 'gridmanager-react/css/gm-react.css';

  • 通过script标签引入

    <link rel="stylesheet" href="../node_modules/gridmanager-react/css/gm-react.css"> <script src="../node_modules/gridmanager-react/js/gm-react.js"></script>

示例

1<div id="example"></div> 2 3 4import ReactDOM from 'react-dom'; 5import React, { useState } from 'react'; 6import ReactGridManager, { $gridManager } from 'gridmanager-react'; 7import 'gridmanager-react/css/gm-react.css'; 8 9// 组件: 操作列 10function ActionInner(props) { 11 const actionAlert = event =&gt; { 12 alert('操作栏th是由React模板渲染的'); 13 }; 14 return <span onclick="{actionAlert}" style="{{display:" 'block', color: 'red'}}>{props.text}</span>; 15} 16 17function ActionComponents(props) { 18 return <actioninner text="{props.text}/">; 19} 20 21// 组件: 空模板 22function EmptyTemplate(props) { 23 return ( 24 <section style="{{textAlign:" 'center'}}> 25 {props.text} 26 </section> 27 ); 28} 29 30// 组件: 标题 31function TitleComponents(props) { 32 return ( 33 <a href="{'https://www.lovejavascript.com/#!zone/blog/content.html?id='" + props.row.id} target="{'_black'}">{props.row.title}</a> 34 ); 35} 36 37// 组件: 类型 38function TypeComponents(props) { 39 // 博文类型 40 const TYPE_MAP = { 41 '1': 'HTML/CSS', 42 '2': 'nodeJS', 43 '3': 'javaScript', 44 '4': '前端鸡汤', 45 '5': 'PM Coffee', 46 '6': '前端框架', 47 '7': '前端相关' 48 }; 49 return ( 50 <button>{TYPE_MAP[props.type]}</button> 51 ); 52} 53 54// 组件: 删除 55function DeleteComponents(props) { 56 const {index, row} = props; 57 const deleteAction = event =&gt; { 58 if(window.confirm(`确认要删除当前页第[${event.target.getAttribute('data-index')}]条的['${event.target.title}]?`)){ 59 console.log('----删除操作开始----'); 60 $gridManager.refreshGrid(option.gridManagerName); 61 console.log('数据没变是正常的, 因为这只是个示例,并不会真实删除数据.'); 62 console.log('----删除操作完成----'); 63 } 64 }; 65 66 return ( 67 <span classname="{'plugin-action'}" onclick="{deleteAction}" data-index="{index}" title="{row.title}">删除</span> 68 ); 69} 70 71// 表格组件配置 72const option = { 73 gridManagerName: 'testReact', 74 height: '100%', 75 emptyTemplate: <emptytemplate text="{'这个React表格," 什么数据也没有'} />, 76 columnData: [{ 77 key: 'pic', 78 remind: 'the pic', 79 width: '110px', 80 text: '缩略图', 81 template: (pic, row) =&gt; { 82 return ( 83 <img style="{{width:" '90px', margin: '0 auto'}} src="{'https://www.lovejavascript.com'" + pic} title="{row.name}/"> 84 ); 85 } 86 },{ 87 key: 'title', 88 remind: 'the title', 89 text: '标题', 90 template: <titlecomponents /> 91 },{ 92 key: 'type', 93 remind: 'the type', 94 text: '分类', 95 align: 'center', 96 template: (type, row, index) =&gt; { 97 return <typecomponents type="{type}/">; 98 } 99 },{ 100 key: 'info', 101 remind: 'the info', 102 text: '使用说明' 103 },{ 104 key: 'username', 105 remind: 'the username', 106 text: '作者', 107 // 使用函数返回 dom node 108 template: (username, row, index) =&gt; { 109 return ( 110 <a href="{'https://github.com/baukh789'}" target="{'_black'}">{username}</a> 111 ); 112 } 113 },{ 114 key: 'createDate', 115 remind: 'the createDate', 116 width: '100px', 117 text: '创建时间', 118 sorting: 'DESC', 119 // 使用函数返回 htmlString 120 template: function(createDate, rowObject){ 121 return new Date(createDate).toLocaleDateString(); 122 } 123 },{ 124 key: 'lastDate', 125 remind: 'the lastDate', 126 width: '120px', 127 text: '最后修改时间', 128 sorting: '', 129 // 使用函数返回 htmlString 130 template: function(lastDate, rowObject){ 131 return new Date(lastDate).toLocaleDateString(); 132 } 133 },{ 134 key: 'action', 135 remind: 'the action', 136 width: '100px', 137 disableCustomize: true, 138 text: <actioncomponents text="{'操作'}/">, 139 // 快捷方式,将自动向组件的props增加row、index属性 140 template: <deletecomponents /> 141 }], 142 supportRemind: true, 143 isCombSorting: true, 144 supportAjaxPage: true, 145 supportSorting: true, 146 ajax_data: 'http://www.lovejavascript.com/blogManager/getBlogList', 147 ajax_type: 'POST', 148}; 149 150// 渲染回调函数 151const callback = query =&gt; { 152 console.log('callback =&gt; ', query); 153}; 154 155ReactDOM.render( 156 <reactgridmanager option="{option}" callback="{callback}" />, 157 document.querySelector('#example') 158);

调用公开方法

> 通过ES6语法,将$gridManager引入。

1import { $gridManager } from 'gridmanager-react'; 2 3// 刷新 4$gridManager.refreshGrid('testReact'); 5 6// 更新查询条件 7$gridManager.setQuery('testReact', {name: 'baukh'}); 8 9// ...其它更多请直接访问API

查看当前版本

1import GridManagerReact, {$gridManager} from 'gridmanager-react'; 2console.log('GridManagerReact 的版本=&gt;', GridManagerReact.version); 3console.log('GridManager 的版本=&gt;', $gridManager.version);

</actioncomponents></typecomponents></actioninner>

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )