id="tblEditabel"
and in the rows which will work with double click I put the class class="editavel"
, in this way only the fields with the class will be edited, I am using mysql
commands to query the bank. It follows the form you are in today.
$(document).ready(function() {
$('#tblEditavel tbody tr td.editavel').dblclick(function() {
if ($('td > input').length > 0) {
return;
}
var conteudoOriginal = $(this).text();
var novoElemento = $('<input/>', {
type: 'text',
value: conteudoOriginal
});
$(this).html(novoElemento.bind('blur keydown', function(e) {
var keyCode = e.which;
var conteudoNovo = $(this).val();
if (keyCode == 13 && conteudoNovo != '' && conteudoNovo != conteudoOriginal) {
var objeto = $(this);
$.ajax({
type: "POST",
url: "atualiza_tipo.html",
data: {
id: $(this).parents('tr').children().first().text(),
campo: $(this).parent().attr('title'),
valor: conteudoNovo
}, //added this comma here
success: function(result) {
objeto.parent().html(conteudoNovo);
$('body').append(result);
}
})
} else if (keyCode == 27 || e.type == 'blur'){
$(this).parent().html(conteudoOriginal);
}
}));
$(this).children().select();
//} removed the extra } from here.
});
})
table, td{
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><tableid="tblEditavel" class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Tipo</th>
<th>Nome</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td title="Nome" class="editavel">Gerente</td>
<td>Fulano</td>
<td>01/10/2007</td>
</tr>
</tbody>
</table>
Note that by double-clicking on the type column it inserts an input to insert any other type, what I would like would be to limit editing, I can insert the select but I am not getting popular the options, I know it will have to be something in ajax and this is my great difficulty.