简体   繁体   English

如何在我的数据表 ajax 服务器端数据中添加下拉列表,以使用数据表列显示到表中

[英]How to add dropdown in my datatable ajax serverside data in showing to table using datatable columns

I'm new to datatable ajax serverside data fething uisng php jquery ajax.我是数据表 ajax 服务器端数据的新手,使用 php jquery Z27705A883ACE206. I have to fetch data but now I want to add a dropdown in some columns to submit the data for a particular row.我必须获取数据,但现在我想在某些列中添加一个下拉列表以提交特定行的数据。

In my table column with the name of "QA Status", I want to add a dropdown to every row.在名为“QA Status”的表格列中,我想为每一行添加一个下拉列表。

and the dropdown option is 1) Pending 2) Accepted 3) Rejected并且下拉选项是 1) 待定 2) 接受 3) 拒绝

See the image看图片

I want to add dropdown using jquery datatable using columns我想使用 jquery 数据表使用列添加下拉列表

This is my code for showing the data in the table这是我在表格中显示数据的代码

"columns": [
            {
              "render": function(data, type, full, meta) {
                return "";
              }
            },
            { "data": "created_at" },
            { "data": "campaign" },
            { data: null, render: function ( data, type, row ) {
                    return data.fname+' '+data.lname;
                } 
            },
            { "data": "c_name" },
            { "data": "qa_status" },
            { "data": "qa_resone" },
            { "data": "client_status" },
            { "data": "client_resone" },
            { "data": "score" }
        ]

In this code { "data": "qa_status" } I want to show a dropdown and I want also to add submit button in the last column of every row for selected value submitted without page reloading.在这段代码中 { "data": "qa_status" } 我想显示一个下拉列表,并且我还想在每行的最后一列中添加提交按钮,以便在不重新加载页面的情况下提交所选值。

please help me.请帮我。

try adding following and see if that works:尝试添加以下内容,看看是否有效:

put following code inside datatable option:将以下代码放入数据表选项中:

let data_table = $(".table_class").DataTables({

    columns: [
        ...
    ],

    initComplete: function() {
        this.api().columns().every(function() {
            var column = this;
            var select = $('<select style="width:100%;"><option value="">Select</option></select>')
                .appendTo($(column.footer()).empty())
                .on('change', function() {
                    var val = $.fn.dataTable.util.escapeRegex($(this).val());
                    column.search(val ? '^' + val + '$' : '', true, false).draw();
                });
            column.draw(false).data().unique().each(function(d, j) {
                select.append('<option value="' + d + '">' + d + '</option>')
            });
        });
    },

});

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

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