How to Insert ID of row inside the button with editor?
How to Insert ID of row inside the button with editor?
User123456
Posts: 57Questions: 15Answers: 0
I know how to do with datatables, however with the editor returns the href location.id=undefined.
How can I fix that to show the corresponding id of the row?
I tried to insert in the full, the name of the ID in table, however didn't work yet.
This is the code for bootstrap.html:
<script type="text/javascript" language="javascript" class="init">
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../php/staff.php",
table: "#publicationTable",
fields: [ {
label: "Visualizado:",
name: "p.status"
}, {
label: "Título da Publicação:",
name: "ti.PublicationTitle"
}, {
label: "Tipo de Publicação:",
name: "ty.PublicationType"
}, {
label: "Ano:",
name: "p.ano"
}, {
label: "Mês:",
name: "p.competencia"
}, {
label: "Empresa:",
name: "c.razaoSocial"
}, {
label: "Favorecido:",
name: "e.nome"
}, {
label: "Botões de Controle:",
name: "p.id_Publication"
}
]
} );
var table = $('#publicationTable').DataTable( {
lengthChange: true,
ajax: "../php/staff.php",
columns: [
{ data: "p.status",
render: function ( data, type, row ) {
var text = "";
if (type == "display") {
if (data == "1") {
text = "<i class='ace-icon fa fa-circle'></i>";
} else {
text = "<i class='ace-icon fa fa-rocket'></i>";
}
data = text
}
return data;
}
},
{ data: "ti.PublicationTitle" },
{ data: "ty.PublicationType" },
{ data: "p.ano" },
{ data: "p.competencia" },
{ data: "c.razaoSocial" },
{ data: "e.nome" },
{ data: "p.id_Publication",
render: function(data, type, full){
return '<a data-toggle="modal" data-target="#infoModal" data-id="' + full['p.id_Publication'] + '" id="getCompany" class="blue"><i class="ace-icon fa fa-search-plus bigger-130"></i></a> <a class="red" href="deleteCompany.php?id_Company=' + full['p.id_Publication'] + '"><i class="ace-icon fa fa-trash-o bigger-130"></i></a> <a class="orange" data-id="' + full['p.id_Publication'] + '" id="blockCompany"><i class="ace-icon fa fa-eye-slash bigger-130"></i></a>';
}
}
],
} );
} );
</script>
And this is for staff.php:
<?php
include( "../../php/Datatables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
Editor::inst( $db, 'tbl_publication AS p', 'id_Publication' )
->fields(
Field::inst( 'p.status' ),
Field::inst( 'ti.PublicationTitle' ),
Field::inst( 'ty.PublicationType'),
Field::inst( 'p.ano' ),
Field::inst( 'p.competencia' ),
Field::inst( 'c.razaoSocial' ),
Field::inst( 'e.nome'),
Field::inst( 'p.id_Publication')
)
->leftJoin( 'tbl_ptitle AS ti', 'p.fk_titulo', '=', 'ti.id_PublicationTitle' )
->leftJoin( 'tbl_ptype AS ty', 'p.fk_tipo', '=', 'ty.id_PublicationType' )
->leftJoin( 'tbl_company AS c', 'p.fk_empresa', '=', 'c.id_Company' )
->leftJoin( 'tbl_employee AS e', 'p.fk_empregado', '=', 'e.id_Employee' )
->process($_POST)
->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
What you are trying to do looks pretty similar to this example https://editor.datatables.net/examples/api/checkbox.html
Your inline button or modal would be the checkbox in the example. I would take a look at the other API examples as well: https://editor.datatables.net/examples/api/index.html
But I just want to insert the id of the
<tr>
inside the button. Do I need to return an entire JSONID to achieve this?What I'm doing wrong in using this?
data-id="' + full['p.id_Publication'] + '"
I looked in the checkbox, however didn't find very similar @rf1234.
Hello @allan , I tried the following too, however didn't worked, if you can help me again.
However it returns undefined.
Change
full['p.id_Publication']
to befull.p.id_Publication
.Allan