0
I want to take the value of the column and store it in a variable.
This code below works perfectly, however I now need to fill the value of the hidden field with the ID that comes from the bank:
"columns": [
{ "data": "cpf" },
{ "data": "nome" , },
{ "data": "sobrenome" , },
{ "data": "celular" },
{ "data": "email" },
{
"data": null,
"defaultContent": "<form method=\"post\" action=\"\"><input type=\"hidden\" id=\"idcontrib\" name=\"idcontrib\" value=\" => "DATA": "ID" <= \"><button type=\"submit\" class=\"btn btn-warning btn-xs\" name=\"edit_contrib\">Editar</button> <button type=\"submit\" class=\"btn btn-danger btn-xs\" name=\"exc_contrib\">Excluir</button></form>"
},
I have to make that part of the code:
value=\" => "DATA": "ID" <= \"
Be something like:
value=\"<?=$id?>\"
For this I have to make the value that comes from the bank be stored in the variable:
$id = "data" : "id";
Something like this is possible ?
HTML
<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th>CPF</th>
<th>Nome</th>
<th>Sobrenome</th>
<th>Celular</th>
<th>email</th>
<th>Ação</th>
</tr>
</thead>
</table>
javascript
<script type="text/javascript">
$(document).ready(function() {
var otable = $('#datatable_fixed_column').DataTable({
"processing": true,
"serverSide": true,
"ajax": "server_processing/contribuintes.php",
"order": [[ 1, "asc" ]],
"columns": [
{ "data": "cpf" },
{ "data": "nome" , },
{ "data": "sobrenome" , },
{ "data": "celular" },
{ "data": "email" },
{
"data": null,
"defaultContent": "<form method=\"post\" action=\"\"><input type=\"hidden\" id=\"idcontrib\" name=\"idcontrib\" value=\"<id>\"><button type=\"submit\" class=\"btn btn-warning btn-xs\" name=\"edit_contrib\">Editar</button> <button type=\"submit\" class=\"btn btn-danger btn-xs\" name=\"exc_contrib\">Excluir</button></form>"
},
],
"columnDefs": [
{ "width": "10%", "targets": 0 },
{ "width": "15%", "targets": 1 },
{ "width": "25%", "targets": 2 },
{ "width": "10%", "targets": 3 },
{ "width": "25%", "targets": 4 },
{ "width": "15%", "targets": 5 },
],
"sDom": "<'dt-toolbar'<'col-xs-6'f><'col-xs-6'<'toolbar'>>r>"+
"t"+
"<'dt-toolbar-footer'<'col-xs-6'i><'col-xs-6'p>>"
});
$("div.toolbar").html('<div class="text-right"><form method="post" action=""><button type="submit" class="btn btn-success" name="add">ADICIONAR NOVO CONTRIBUINTE</button></form></div>');
})
Server-side script
$table = 'tbl_contribuintes';
$primaryKey = 'id_contrib';
$columns = array(
array( 'db' => 'cpf', 'dt' => 'cpf' ),
array( 'db' => 'fnome', 'dt' => 'nome' ),
array( 'db' => 'lnome', 'dt' => 'sobrenome' ),
array( 'db' => 'celular1', 'dt' => 'celular' ),
array( 'db' => 'email', 'dt' => 'email' ),
array( 'db' => 'id_contrib', 'dt' => 'id' )
);
$sql_details = array(
'user' => 'root',
'pass' => 'XXXXX',
'db' => 'XXXXX',
'host' => 'localhost'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
Remembering that the data are being listed perfectly, just missing even this detail to take the value of the column and put in the variable.
Thank you very much.
Is this a JSON you generate in PHP? How are you doing to generate? You would need to include the ID before converting to JSON, but not knowing how/when you do it makes it difficult to answer.
– bfavaretto
My friend, I’m sorry, I’ve posted so much on this q ended up summarizing too much. I’ll edit the post for you to take a look
– theteo
bjavaretto, aguaardando a help your or some illuminated
– theteo
I don’t know this SSP class of yours (I don’t know what it does), nor did I understand when the data of the database comes in. I wouldn’t know how to help...
– bfavaretto
I’m actually using the DATATABLE component
– theteo