Grid.js原生环境增加选行功能

Grid.js 原生环境中通过plugins增加选行功能

Grid.js has an internal pipeline which takes care of processing, filter and refining the raw data. You can get access to the current pipeline by using config.pipeline (via the useConfig hook) or you can use the useSelector hook to subscribe to a specific part of Grid.js state.

典型的grid.js plugins模板如下

function TotalSalaryPlugin() {
  const [total, setTotal] = useState(0);
  const data = useSelector((state) => state.data);
  useEffect(() => {
    if (!data) return;
    setTotal(data.toArray().reduce((prev, row) => prev + row[1], 0));
  }, [data]);
  return h('b', {}, `Total: $${total.toLocaleString()}`);
}

注意点:

使用selection插件需要采用正确的引入,我因为引用的是umd格式的
组件的名称为 gridjs.plugins.selection.RowSelection

<!DOCTYPE html>
<html>
<head>
	<title>grid simple</title>
	<script type="text/javascript" src='js/gridjs.js'></script>
	<script type="text/javascript" src='js/selection.umd.js'></script>
	<link
      href="css/mermaid.min.css"
      rel="stylesheet"
    />
</head>
<body>
	<div id="wrapper"></div>
	<script type="text/javascript">
		const grid = new gridjs.Grid({
		  columns: [
		  {
	        id: 'awesomeCheckbox',
	        name: 'Select',
	        plugin: {
	          component: gridjs.plugins.selection.RowSelection
	        }
	      },
		  'Name', 'Email', 'Phone Number'],
		  sort: true,
		  data: [
		    ['John', 'john@example.com', '(353) 01 222 3333'],
		    ['Mark', 'mark@gmail.com',   '(01) 22 888 4444']
		  ]
		}).render(document.getElementById("wrapper"));

		grid.config.store.subscribe(function (state) {
		  console.log('checkbox updated', state.rowSelection);
		})
	</script>
</body>
</html>

辅助功能(排序):

sort: true,

事件处理:

grid.config.store.subscribe(function (state) {
	console.log('checkbox updated', state.rowSelection);
})

运行如下

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值