Webgrid中的复选框时如何获取行值

时间:2019-03-12 10:22:31

标签: jquery

我想在Webgrid中选中一个复选框时从一行中获取值,这是我为其编写的代码

$("#check_all").click(function () {
        var ischecked = this.checked;
        $('#FeesListTable').find("input:checkbox").each(function () {
            this.checked = ischecked;
            var values = new Array();
            $.each($("input[name='ids']:checked"), function () {
                var data = $(this).parents('tr:eq(0)');
                values.push({ 'tkrate': $(data).find('td:eq(3)').text(), 'hoursworkedunit': $(data).find('td:eq(4)').text() });
            });

            console.log(values);
            
        });
    });

    //3rd click event for checkbox of each row
    $("input[name='ids']").click(function () {
        var totalRows = $("#FeesListTable td :checkbox").length;
        var checked = $("#FeesListTable td :checkbox:checked").length;
        alert(totalRows);
        alert(checked);
        if (checked == totalRows) {
            $("#FeesListTable").find("input:checkbox").each(function () {
                this.checked = true;
                var values = new Array();
                $.each($("input[name='ids']:checked"), function () {
                    var data = $(this).parents('tr:eq(0)');
                    values.push({ 'tkrate': $(data).find('td:eq(3)').text(), 'hoursworkedunit': $(data).find('td:eq(4)').text() });
                });

                console.log(values);
                alert(values);

            });
        }
        else {
            $("#check_all").removeAttr("checked");
        }
    });


Above code is the sample function whic i write for the checkbox

And my id for the webgrid is
**<div id="divInvoiceFeeslistById" style="overflow-x:auto;">**

And for checkbox column in Webgrid



<!-- begin snippet: js hide: false console: true babel: false -->
grid.Column(header:"{CheckFeesList}", format: @<text><input type="checkbox" name="chkRow" id="ckbxDailyActivityFees" value="@item.ClientMatterId"/> </text>  )).ToString()
.Replace("{CheckFeesList}", "<label class='checkbutton' data-toggle='tooltip'  title='Select the Invoice fees' > <input  type='checkbox' id='check_all' class='checkmark_th' name='ids' /><span class='checkmark' style='left: 20px; '></span></label>"))

                                      

0 个答案:

没有答案