4
Hello I have a dynamic table that works very well, but as the field is an input people can type anything, but wanted to limit this edition using the options of the options, the table I use the id="tblEditabel"
and on the lines that will work with double click I put the class class="editavel"
, so only fields with class will be edited, I am using commands mysql
for consultation with the bank. It follows the form it is 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>
<table id="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>
notice that when double clicking on the column type the same inserts an input to insert any other type, what I wanted would be to limit editing, I can insert the select but I’m not getting popular the options, I know it will have to be something in ajax and this is my great difficulty.
You can load an object with this information?
– novic
But exactly what is your difficulty when including options with call data
Ajax
? Already have a call that returns the data? In your code you already have a callAjax
, It wouldn’t be much different than that. Here’s a simple example that can help you: http://www.devmedia.com.br/populando-selects-dynamicamente-com-ajax-json-e-php/27658– Ricardo Pontual
Good morning @Virgilionovic as it is I work normally, the information entered in the input is saved to the bank without further complication.
– WMomesso