【问题标题】:Get id from record using Editor Datatables使用编辑器数据表从记录中获取 id
【发布时间】:2019-04-08 17:28:16
【问题描述】:

我正在使用数据表编辑器,我想创建一个自定义列来获取记录的 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: '&lt;a href="" class="btn btn-primary" style="background-color:#5079d7"&gt;&lt;i class="fas fa-search-plus"&gt;&lt;/i&gt;'+editor.field('nome').get()+'&lt;/a&gt;', searchable: false } 中,我尝试在我的标签 a 上获取字段“nome”的值。

有什么想法吗?

【问题讨论】:

    标签: jquery datatables


    【解决方案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,可以作为基础。如果它不起作用,请告诉我我能做什么,或者如果有疑问......

    【讨论】:

    • Valeu mesmo cara。 Faz uns 8 dias que estou quebrando a cabeça com isso。
    • grato pela atenção ^^
    猜你喜欢
    • 2013-08-20
    • 2020-07-26
    • 2018-02-17
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多