如何从数据表中获取单元格值?单元格值

时间:2020-08-28 07:17:57

标签: javascript html jquery datatable datatables

data table image capture

我使用数据表单元格内的复选框,并选中一个或多个复选框后,显示“添加”按钮进行更改。但是我的问题是我在选中复选框后无法从单元格中获取值。如果我可以采用已选中复选框的值,则可以将其发送到数据表中进行必要的更改

<td class="denetleme">
    <div class="vs-checkbox-con vs-checkbox-success">
        <input class="selectAll_1 selectinput" type="checkbox" value="true" >
        <span class="vs-checkbox">
            <span class="vs-checkbox--check">
                <i class="vs-icon feather icon-check"></i>
            </span>
        </span>
    </div>
</td>

如果一行中选中了一个或多个复选框,则还要选中这些复选框和列ID

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用.selectinput

获取单元格的全部数据
$('#mytable .selectinput').each(function() {
  alert($(this).html());
});

答案 1 :(得分:0)


    $('#saveBtn').click(function () {
 
        var dataArr = [];
        $.each($("#genelTablo tr.selected td.checkElement input.selectinput"), function () { //get each tr which has selected class

            
            var getColumnOfTd = $(this).closest("td")
            
            console.log("column", table.cell(getColumnOfTd).index().column, table.cell(getColumnOfTd).index().row)
            dataArr.push({
                columnName: $(this).closest("tr").find("td:first-child").text(),
                columnId: table.cell(getColumnOfTd).index().column,
                rowId: table.cell(getColumnOfTd).index().row,
                inputValue: $(this).val()
            })
 
            //dataArr.push($(this).find('td.checkElement input').val()); //find its first td and push the value
            //dataArr.push($(this).find('td:first').text()); You can use this too
        });
        console.log("here",dataArr);

 
 
    });

相关问题