0
votes

I am using the Datatables Editor and I want to create a custom column that get the id of the record. The code is:

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 },
    ]
});

My custom field is in { 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 } and I try to get the value of field 'nome' on my tag a.

Any idea?

1

1 Answers

1
votes

i'm brazilian. Try this:

    {
            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>';
            }       
    }

so will have the ID, can use as base. If it does not work let me know what I can do, or if there is doubt ...