使用编辑器数据表从记录中获取ID

时间:2019-04-08 17:28:17

标签: jquery datatables

我正在使用数据表编辑器,并且想要创建一个自定义列来获取记录的ID。代码是:

editor = new $.fn.dataTable.Editor({
    ajax: "assets/dados/tabelaProfissionais.php",
    table: "#tabelaProfissionais",
    fields: [
        { label: "CPF:", name: "cpf", type: "mask", mask: "000.000.000-00" },
        { label: "Nome:", name: "nome" },
        { label: "Telefone:", name: "telefone", type: "mask", mask: "(00)00000-0000" },
        { label: "Endereço:", name: "endereco" },
        { label: "CNS:", name: "cns", type: "mask", mask: "000000000000000" },
        { label: "RG:", name: "rg" },
        { label: "Sexo:", name: "sexo", type: "select", options: [
            { label: "Feminino",  value: "F" },
            { label: "Masculino", value: "M" }
        ]},
        { label: "Conselho:", name: "conselho" },
        {
            label: "Image:",
            name: "imagem",
            type: "upload",
            display: function ( file_id ) {
                return '<img src="'+editor.file( 'files', file_id ).web_path+'"/>';
            },
            clearText: "Clear",
            noImageText: 'Em imagem'
        }
    ],

$('#tabelaProfissionais').DataTable({
    dom: "Bfrtip",
    ajax: {
        url: "assets/dados/tabelaProfissionais.php",
        type: "POST"
    },
    serverSide: true,
    columns: [
        { data: "cpf" },
        { data: "nome" },
        { data: null, defaultContent: '<a href="" class="btn btn-primary" style="background-color:#5079d7"><i class="fas fa-search-plus"></i>'+editor.field('nome').get()+'</a>', searchable: false }
    ],
    select: true,
    buttons: [
        { extend: "create", editor: editor  },
        { extend: "edit",   editor: editor },
    ]
});

我的自定义字段位于{ data: null, defaultContent: '<a href="" class="btn btn-primary" style="background-color:#5079d7"><i class="fas fa-search-plus"></i>'+editor.field('nome').get()+'</a>', searchable: false }中,我尝试在标签a上获取字段“ nome”的值。

有什么主意吗?

1 个答案:

答案 0 :(得分:1)

我是巴西人。试试这个:

    {
            data: 'user_id',
            render: function ( data, type, row, meta ) {
                return '<a href="" class="btn btn-primary" style="background-color:#5079d7"><i class="fas fa-search-plus"></i>'+(data)+'</a>';
            }       
    }

因此将具有ID,可以用作基础。如果它不起作用,请让我知道我能做什么,或者是否有疑问...