How to get the selected row value of table table in layui

下次还敢
Release: 2024-04-04 03:00:19
Original
808 people have browsed it

How to use layui to get the value of the selected row in the table

In layui, the method of getting the value of the selected row in the table is as follows:

1. Get the current All selected rows

layui.table.checkStatus('tableId');
Copy after login

2. Get the currently selected row data

let data = layui.table.checkStatus('tableId').data;
Copy after login

3. Get the currently selected row index

let index = layui.table.checkStatus('tableId').index;
Copy after login

Among them, tableId is the container ID of the table.

Sample code:

layui.use('table', function () {
  var table = layui.table;

  // 获取表格实例
  let instance = table.render({
    elem: '#test-table',
    data: [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Doe' }],
    cols: [[{ type: 'checkbox' }, { field: 'id', title: 'ID' }, { field: 'name', title: '姓名' }]]
  });

  // 获取当前选中的行
  let data = table.checkStatus('test-table').data;

  // 输出选中行的姓名
  console.log(data[0].name); // John Doe
});
Copy after login

The above is the detailed content of How to get the selected row value of table table in layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!