使用server_processing.php填充数据表中的textarea

时间:2017-03-30 10:25:34

标签: jquery datatables

我有一个数据表,我希望它上面的列可以作为textarea进行编辑,但我发现很难填充这个textarea。我能够激活按钮提交,因为这不是我第一次这样做,但我觉得填充textarea不会离它很远。如果我能得到任何帮助,我将不胜感激:

这是我的代码:

$(document).ready(function(){
        var table = $('#admin_table').DataTable({
            //"order": [[ 2, "desc" ]],
            "processing": true,
            "serverSide": true,
            "ajax": $.fn.dataTable.pipeline({
                url: 'server_processing.php',
                pages: 5 // number of pages to cache
            }),

           "columnDefs": [ {
                "targets": 9,
                "data": null,
                "defaultContent": "<div class='w3-btn-group w3-vertical w3-center'><a id='edit_fact' class='w3-btn w3-padding w3-slim w3-small w3-black w3-text-white w3-ripple w3-card-8 w3-hover-orange w3-hover-text-black' title='Edit Fact'><span class='glyphicon glyphicon-pencil w3-center'></span></a> <a id='delete_fact' class='w3-btn w3-padding w3-slim w3-small w3-white w3-text-blue w3-ripple w3-card-8 w3-hover-red w3-hover-text-black' title='Delete Fact'><span class='glyphicon glyphicon-trash w3-center'></span></a></div>"
            },
                    {
                "targets": 3,
                "data": true,
                "defaultContent": "<textarea name='diagnosis' id='diagnosis' ></textarea>"  
                    }        
        ]


        });

         $('#admin_table tbody').on('click', '#edit_fact', function () {
            var data = table.row( $(this).parents('tr') ).data();
//Where i submit my edits
            });

// Populating the text area
            var data = table.row( $('#admin_table).parents('tr') ).data();
            $('#diagnosis').val(data[3]);

    });

我的表格如下: My datatable

1 个答案:

答案 0 :(得分:0)

哦,是的,我设法使用render

让它工作

以下是代码:

var table = $('#admin_table').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": $.fn.dataTable.pipeline({
            url: 'scripts/server_processing.php',
            pages: 5 // number of pages to cache
        }),

       "columnDefs": [ {
            "targets": 9,
            "data": null,
            "defaultContent": "<div class='w3-btn-group w3-vertical w3-center'><a id='edit_fact' class='w3-btn w3-padding w3-slim w3-small w3-black w3-text-white w3-ripple w3-card-8 w3-hover-orange w3-hover-text-black' title='Edit Fact'><span class='glyphicon glyphicon-pencil w3-center'></span></a> <a id='delete_fact' class='w3-btn w3-padding w3-slim w3-small w3-white w3-text-blue w3-ripple w3-card-8 w3-hover-red w3-hover-text-black' title='Delete Fact'><span class='glyphicon glyphicon-trash w3-center'></span></a></div>"
        },
        {
            "targets": 3,
            "render": function ( data, type, row ) {
                    return "<textarea name='diagnosis' id='diagnosis' >"+data+"</textarea>";
                }  
        }        
    ]


    });