Home > Article > Web Front-end > How to get the selected row value of table table in layui
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>
2. Get the currently selected row data
<code class="javascript">let data = layui.table.checkStatus('tableId').data;</code>
3. Get the currently selected row index
<code class="javascript">let index = layui.table.checkStatus('tableId').index;</code>
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>
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!