选中的Jquery数据表复选框附加到输入字段

时间:2017-07-21 09:12:55

标签: javascript jquery

btnSearchName将打开一个包含搜索结果表的模态,然后每行都有复选框进行选择,然后点击btnSubmit后,模态将关闭并且必须将所选的ssn_or_tin列放在输入字段中,如'123 ,645,936,743',我已经尝试了很多代码但没有工作,请帮忙

$('#btnSearchName').on("click", function() {
    Namestable = $('#NamesDatatable').DataTable({
        "processing": true,
        'select': {
            'style': 'multi'
        },
        'order': [[1, 'asc']],
        dom: "<'row'<'col-sm-6'l><'col-sm-6'f>>" +
            "<'row'<'col-sm-12'tr>>" +
            "<'row'<'col-sm-6'i><'col-sm-6'p>>",
        "ajax": {
            "url": '/Home/GetAllCusname',
            "type": "POST",
            "datatype": "json",
            "data": function (d) {
                d.searchParameters = {};
                d.searchParameters.name = $('#txtName').val();
            }
        },
        "columns": [
            {
                defaultContent: '',
                className: 'select-checkbox',
                'checkboxes': {
                    'selectRow': true
                },
                orderable: false
            },
            { "data": "ssn_or_tin", "autoWidth": true },
            { "data": "name", "autoWidth": true }
        ]
    });
});

$('#btnSubmit').on("click", function () {
    var rows_selected = Namestable.column(0).checkboxes.selected(); //i have not tested this line of code yet if it's working,
                            maybe there is another way of getting the selected checkbox, maybe by their class if they have the 'selected' class

    $.each(rows_selected, function () {
        $('#txtSSNTIN').append(
            //I don't know what code to put here, it must append the 
            'ssn_or_tin' values like '123, 953, 673' in the input field with 
             the id 'txtSSNTIN'
        );
    });
});

1 个答案:

答案 0 :(得分:0)

您可以在DataTable中尝试Onrowbound。你不必指定这些东西