jquery - 使用编辑器数据表从记录中获取 id
问题描述
我正在使用数据表编辑器,我想创建一个自定义列来获取记录的 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”的值。
任何的想法?
解决方案
我是巴西人。试试这个:
{
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,可以用作基础。如果它不起作用,请告诉我我能做什么,或者如果有疑问......
推荐阅读
- r - 无法使用 geom_contour() 在 R 中绘制决策边界
- customization - 如何使用 android studio 在 mapbox 中自定义语音指令?
- python - 获取第三方模块的未定义模块错误
- laravel - 使用 laravel livewire 将焦点转移到另一个领域
- c - 货币转换代码不起作用 - 如何比较字符串
- sharepoint - C# 的图形 API:尝试在 Office 365 上创建团队时的 BadGateway 结果
- python - 安装有 Pip 问题的 `pygame`
- flutter - 如何在颤振中重新启动整个应用程序?
- node.js - 什么是好的通知模型?
- javascript - 将修改后的表发送到 ASP.NET MVC 中的控制器?