Created
February 22, 2018 06:02
-
-
Save camilamoreiradev/8cc7669418739b28788df64e6dafddae to your computer and use it in GitHub Desktop.
Criar um botão e passar o id do produto para uma função ajax que vai carregar no modal os dados do item com id informado.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############### COLOCAR ESSE CÓDIGO NO BLANK ############### | |
$x = array(); | |
if(isset($_POST['id'])) { | |
$sql = "SELECT region, customer_name, sales, product FROM sales WHERE id = ".$_POST['id']; | |
sc_select(rs, $sql); | |
$x['region'] = $rs->fields[0]; | |
$x['customer'] = $rs->fields[1]; | |
$x['sales'] = $rs->fields[2]; | |
$x['product'] = $rs->fields[3]; | |
echo json_encode($x); | |
} | |
############### COLOCAR ESSE CÓDIGO NO ONREADER DA GRID(CONSULTA) ############### | |
{view_modal} = '<button produto-id="'.{ID}.'" type="button" class="btn btn-info click-produto" data-toggle="modal" data-target="#myModal">Detalhes</button>'; | |
############### COLOCAR ESSE CÓDIGO NO ONHEADER DA GRID(CONSULTA) - PRECISA HABILITAR O CABEÇALHO ############### | |
?> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<?php | |
############### COLOCAR ESSE CÓDIGO NO ONFOOTER DA GRID(CONSULTA) - PRECISA HABILITAR O RODAPÉ ############### | |
?> | |
<div class="modal fade" id="myModal" role="dialog" style="display: none !important;"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal">×</button> | |
<h4 id="product-name" class="modal-title"></h4> | |
</div> | |
<div class="modal-body"> | |
<form> | |
<div class="form-group"> | |
<label for="region">Region:</label> | |
<input type="text" class="form-control" id="fregion" disabled /> | |
</div> | |
<div class="form-group"> | |
<label for="cname">Customer Name:</label> | |
<input type="text" class="form-control" id="fname" disabled /> | |
</div> | |
<div class="form-group"> | |
<label for="valor">Valor:</label> | |
<input type="text" class="form-control" id="fvalor" disabled /> | |
</div> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |
<button type="submit" class="btn btn-default">Save</button> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$(".click-produto").click(function() { | |
var _id = $(this).attr("produto-id"); | |
$.ajax({ | |
url: '../blank_getDados/blank_getDados.php', | |
type: 'POST', | |
data: {id: _id}, | |
}) | |
.done(function(a) { | |
var dados = JSON.parse(a); | |
$("#fregion").val(dados['region']); | |
$("#fname").val(dados['customer']); | |
$("#fvalor").val(dados['sales']); | |
$("#product-name").text("Detalhes do produto: "+dados['product']); | |
}); | |
}); | |
}); | |
window.onload = function(){ | |
parent.document.getElementById("CMIframe").height = document.getElementById("main_table_grid").scrollHeight + 50; | |
} | |
</script> | |
<?php | |
PS.: Deixa seu like ou comentário no canal, isso me incentiva a continuar compartilhando e ajudando a comunidade. | |
Thanks! |
Excelente, solo cuando pasas a otro pestaña se queda con el ultimo que utilizaste.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obrigado!!