jQWidgets Forums
jQuery UI Widgets › Forums › Grid › grip does not synchronize with mysql
Tagged: grid, javascript grid, jquery grid
This topic contains 4 replies, has 2 voices, and was last updated by famp 9 years, 3 months ago.
-
Author
-
mysql if incorporating the data, to see the INTRODUCTION I refresh the screen, not done in real time.
<html>
<head>
<link rel=”stylesheet” href=”jqwidgets/styles/jqx.base.css” type=”text/css” />
<link rel=”stylesheet” href=”jqwidgets/styles/jqx.classic.css” type=”text/css” />
<script type=”text/javascript” src=”scripts/jquery-1.11.1.min.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxcore.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxbuttons.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxscrollbar.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxmenu.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxcheckbox.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxlistbox.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxdropdownlist.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxgrid.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxgrid.pager.js”></script>
<script src=”jqwidgets/jqxlistbox.js” type=”text/javascript”></script>
<script src=”jqwidgets/jqxgrid.edit.js” type=”text/javascript”></script>
<script src=”jqwidgets/jqxdropdownlist.js” type=”text/javascript”></script>
<script src=”jqwidgets/jqxcombobox.js” type=”text/javascript”></script>
<script src=”jqwidgets/jqxpanel.js” type=”text/javascript”></script>
<script type=”text/javascript” src=”jqwidgets/jqxgrid.selection.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxgrid.sort.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxdata.js”></script>
<script type=”text/javascript”>
$(document).ready(function () {var data = {};
// prepare the data
var theme = ‘classic’; //temavar source =
{
datatype: “json”,
datafields:
[
{ name: ‘numero’, type: ‘string’},
{ name: ‘nombre’, type: ‘string’},
{ name: ‘hora_llegada’, type: ‘string’},
{ name: ‘hora_fin’, type: ‘string’},
{ name: ‘estado’ , type: ‘string’},
{name: ‘idlista’, type: ‘string’}],
id: ‘idlista’,
cache: false,
url: ‘listas/datos/lista_espera_peluqueros_datos.php’,
root: ‘Rows’,
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server – send update command
var data = “update=true&estado=” + rowdata.estado;
data = data + “&idlista=” + rowdata.idlista;
$.ajax({
dataType: ‘json’,
url: ‘listas/datos/lista_espera_peluqueros_datos.php’,
data: data,
success: function (data, status, xhr) {
// update command is executed.
commit(true);
},
error: function () {
// cancel changes.
commit(false);
}
});
},beforeprocessing: function(data)
{
source.totalrecords = data[0].TotalRows;},
sort: function()
{
// update the grid and send a request to the server.
$(“#jqxgrid”).jqxGrid(‘updatebounddata’, ‘sort’);
},};
var cellclass = function (row, columnfield, value) {
if (value == 0) {
return ‘red’;
}
else if (value == 1) {
return ‘yellow’;
}
else if (value == 2) {
return ‘green’;
}
else if (value == 3) {
return ‘blue’;
}
}var dataadapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$(“#jqxgrid”).jqxGrid(
{
width: ‘100%’,
source: dataadapter,
theme: theme,
autoheight: true,
altrows: true,
enabletooltips: true,
editable: true,
selectionmode: ‘singlecell’,
pageable: true,//paginacion
virtualmode: true,
sortable: false, //ordenacion
rendergridrows: function(params)
{
return params.data;
},
columns: [
{ text: ‘Num.’, datafield: ‘numero’, width: ‘12%’ },
{ text: ‘Nombre’, datafield: ‘nombre’, width: ‘30%’},
{ text: ‘H. llegada’, datafield: ‘hora_llegada’, width: ‘22%’ },
{ text: ‘H. pelado’, datafield: ‘hora_fin’, width: ‘23%’ },
{ text: ‘Estado’,
datafield: ‘estado’,
cellclassname: cellclass,
width: ‘13%’ },
{text: ‘Id’, datafield:’idlista’, hidden:true}
]
});$(‘#jqxgrid’).on(‘cellvaluechanged’, function (event) {
});
});
</script>
</head>
<body class=’default’>
<style>
.green {
color: black\9;
background-color: limegreen\9;
}
.yellow {
color: black\9;
background-color: yellow\9;
}
.red {
color: black\9;
background-color: lightsalmon\9;
}
.blue {
color: black\9;
background-color: cyan\9;
}
.green:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .green:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
color: black;
background-color: limegreen;
}
.yellow:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .yellow:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
color: black;
background-color: yellow;
}
.red:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .red:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
color: black;
background-color: lightsalmon;
}
.blue:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .blue:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
color: black;
background-color: cyan;
}
</style>
<div id=’jqxWidget’>
<div id=”jqxgrid”></div>
</div>
</div></body>
</html>
</html>mysql
#Include the connect.php file
include(‘../../includes/funciones.php’);
#Connect to the databaseechoconexion_pdo($con, $hostname, $database, $username, $password);
// $lista= mostrarLista_peluquero($con);
$lista = $con->query(“SELECT * FROM listas “);
if (isset($_GET[‘update’]))
{
$estado=$_GET[‘estado’];
$id=$_GET[‘idlista’];
$sql = “UPDATE listas SET estado=$estado WHERE id=$id”;
$stmt = $con->prepare($sql);
$stmt->execute(); }
else {
$lista->execute();
$total_rows = $lista->rowCount();
while ($row = $lista->fetch(PDO::FETCH_ASSOC)){
$pendiente_pelado[] = array(
‘numero’ => $row[‘numero’],
‘nombre’ => $row[‘nombre’],
‘hora_fin’ => $row[‘hora_pelado’],
‘hora_llegada’ => $row[‘hora_llegada’],
‘estado’ => $row[‘estado’],
‘idlista’ => $row[‘id’]
);
}$data[] = array(
‘TotalRows’ => $total_rows,
‘Rows’ => $pendiente_pelado
);
echo json_encode($data);}
/* close connection */
$con=FALSE;
?>perdomene, my English is not very advanced.
Google translator
Hi famp,
Grid is a client side widget. The synchronization with your server is done by your server code. I suggest you to check why your server code does not update your DB and debug this part of the code.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comhi thanks for answering.
I have solved by adding another identical query right after the update and before and everything else ok.Hi famp,
Thanks for the update. Could you share your changes for the benefit of the others in the Forum?
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThis is the solution, It connects to the MySQL file stays like this.
EL fichero que realiza la conexion con mysql se queda como este.`include(‘../../includes/funciones.php’);
conexion_pdo($con, $hostname, $database, $username, $password);
// $lista= mostrarLista_peluquero($con);
$lista = $con->query(“SELECT * FROM listas “);
if (isset($_GET[‘update’]))
{
$estado=$_GET[‘estado’];
$id=$_GET[‘idlista’];
$sql = “UPDATE listas SET estado=$estado WHERE id=$id”;
$stmt = $con->prepare($sql);
$stmt->execute();
/*———————————-NEW———————————–*/
$lista->execute();
$total_rows = $lista->rowCount();
while ($row = $lista->fetch(PDO::FETCH_ASSOC)){
$pendiente_pelado[] = array(
‘numero’ => $row[‘numero’],
‘nombre’ => $row[‘nombre’],
‘hora_fin’ => $row[‘hora_pelado’],
‘hora_llegada’ => $row[‘hora_llegada’],
‘estado’ => $row[‘estado’],
‘idlista’ => $row[‘id’]
);
}$data[] = array(
‘TotalRows’ => $total_rows,
‘Rows’ => $pendiente_pelado
);
echo json_encode($data);
}
/*————————————————-END NEW———————————————*/
else {
$lista->execute();
$total_rows = $lista->rowCount();
while ($row = $lista->fetch(PDO::FETCH_ASSOC)){
$pendiente_pelado[] = array(
‘numero’ => $row[‘numero’],
‘nombre’ => $row[‘nombre’],
‘hora_fin’ => $row[‘hora_pelado’],
‘hora_llegada’ => $row[‘hora_llegada’],
‘estado’ => $row[‘estado’],
‘idlista’ => $row[‘id’]
);
}$data[] = array(
‘TotalRows’ => $total_rows,
‘Rows’ => $pendiente_pelado
);
echo json_encode($data);}
/* close connection */
$con=FALSE; -
AuthorPosts
You must be logged in to reply to this topic.