Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table.setRowChecked使用时的问题 #1619

Closed
4 tasks done
zherose opened this issue Feb 3, 2024 · 1 comment
Closed
4 tasks done

table.setRowChecked使用时的问题 #1619

zherose opened this issue Feb 3, 2024 · 1 comment
Labels
usage 用法问题

Comments

@zherose
Copy link

zherose commented Feb 3, 2024

议题条件

  • 我确认已查看官方使用文档:https://layui.dev ,但没有找到相关解决方案。
  • 我确认已在 Issues 中搜索过类似的问题,但没有找到相关解决方案。
  • 我已仔细阅读: 🍀 Layui Issue 贡献指南

议题类型

疑是 BUG

使用版本

V2.9.2

问题描述

我想在点击表格checkbox时,触发表格复选框,并同时选择某个或多个数据相同(订单号相同)的其他行。
我写的代码可以执行,如图所示,当我点击前三行订单 RK20240126-1,会同时选中4行。
但不知道为什么点击第4行,前3行没选中。
是BUG 还是我写的代码有问题?

业务代码

// 触发表格复选框选择
	table.on('checkbox(Receipts)', function(obj){
		//console.log(obj)
		var data = obj.data;
		var id = data.OrderNumber;
		console.log(id)
		//var tabledata = table.cache['Receipts'] || {};
		var tabledata = table.getData('Receipts')
		var i = [];
			tabledata.forEach(function (item, index) {
				if (item.OrderNumber === id) {
					//item.LAY_CHECKED = true
					//console.log(item.OrderNumber)
					i.push(index)
		        }
		    });
		console.log(i)
		if (i.length > 1) {
			table.setRowChecked('Receipts', { index: i});
		}
	});

截图补充

PixPin_2024-02-03_15-16-45

浏览器

Chromium: 98.0.4758.139 Res: 2306.598

演示地址

No response

友好承诺

  • 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护 Layui 良好的社区氛围。
@bxjt123 bxjt123 added the usage 用法问题 label Feb 3, 2024
@bxjt123
Copy link
Collaborator

bxjt123 commented Feb 3, 2024

如果是需要批量选中/取消的,那么push里就不能放入鼠标选中行的下标,因为checkboxchecked默认会自动切换,鼠标选中后又执行一次自动选中会导致原本鼠标选中行被取消选中,用table.checkStatus(id)获取选中行就知道了;
或者判断当前是要选中还是取消,给checked强制赋值也可以。
推荐用第一种,只需要稍微改改即可。

- if (item.OrderNumber === id) {
+ if (item.OrderNumber === id && item.id !== 鼠标选中行id) {

- if (i.length > 1) {
+ if (i.length > 0) {

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage 用法问题
Projects
None yet
Development

No branches or pull requests

3 participants