简体   繁体   English

选中“ jQuery Datatables”复选框追加到输入字段

[英]Jquery Datatables Checkbox selected append to input field

the btnSearchName will open a Modal with table of the search result, then it has checkbox per row to select, then after I click the btnSubmit, the Modal will close and must put the selected ssn_or_tin column in an input field like '123, 645, 936, 743', I already tried many codes but not working, please help 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'
        );
    });
});

You could have try Onrowbound in DataTable. 您可以尝试在DataTable中进行Onrowbound You dont have to specify these things 您不必指定这些东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM