Home > Web Front-end > Layui Tutorial > How to get the selected row value of table table in layui

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

下次还敢
Release: 2024-04-04 03:00:19
Original
997 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

<code class="javascript">layui.table.checkStatus('tableId');</code>
Copy after login

2. Get the currently selected row data

<code class="javascript">let data = layui.table.checkStatus('tableId').data;</code>
Copy after login

3. Get the currently selected row index

<code class="javascript">let index = layui.table.checkStatus('tableId').index;</code>
Copy after login

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

Sample code:

<code class="javascript">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
});</code>
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template