jQWidgets Forums
Forum Replies Created
-
Author
-
July 31, 2013 at 12:28 am in reply to: Delete Row in Grid linked with PHP+MySql Delete Row in Grid linked with PHP+MySql #25976
Many thanks Dimitar!!! now I can delete and Update rows!!! never I had entered to “Build CRUD Web App with jqxGrid using PHP and MySQL” because I didn’t understand what is “CRUD”….
Thanks for your support!!!
best regards!!!,
Damian
Sorry:
data_comercio.php
$row[‘nombre’],
‘categoria’ => $row[‘categoria’],
‘precio’ => $row[‘precio’],
‘descripcion’ => $row[‘descripcion’]);
}$data[] = array(
‘TotalRows’ => $total_rows,
‘Rows’ => $employees
);
echo json_encode($data);
}
?>con_productos:
$(document).ready(function () {
// prepare the data
var data = {};
var theme = ‘classic’;
var source =
{
datatype: “json”,
datafields: [{ name: ‘nombre’ },
{ name: ‘categoria’},
{ name: ‘precio’ },
{ name: ‘descripcion’ },],
url: ‘../scripts/data_productos.php’,
root: ‘Rows’,
beforeprocessing: function (data) {
source.totalrecords = data[0].TotalRows;
},
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server – send update command
var data = “update=true&nombre=” + rowdata.nombre + “&categoria=” + rowdata.categoria + “&precio=” + rowdata.precio;
data = data + “&descripcion=” + rowdata.descripcion;$.ajax({
dataType: ‘json’,
url: ‘../scripts/data_productos.php’,
data: data,
success: function (data, status, xhr) {
// update command is executed.
commit(true);
},
error: function () {
commit(false);
}
});
},
deleterow: function (rowid, rowdata, commit) {
// synchronize with the server – send update command
var data = “delete=true&nombre=” + rowdata.nombre + “&categoria=” + rowdata.categoria + “&precio=” + rowdata.precio;
data = data + “&descripcion=” + rowdata.descripcion;$.ajax({
dataType: ‘json’,
url: ‘../scripts/data_productos.php’,
data: data,
success: function (data, status, xhr) {
//delete command is executed.
commit(true);
},
error: function () {
commit(false);
}
});
}
};
var dataadapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$(“#jqxgrid”).jqxGrid(
{
width: 800,
selectionmode: ‘singlerows’,
source: dataadapter,
theme: theme,
editable: true,
autoheight: true,
pageable: true,
virtualmode: true,rendergridrows: function () {
return dataadapter.records;
},
columns: [
{ text: ‘Nombre’, datafield: ‘nombre’, width: 200 },
{ text: ‘Categoria’, datafield: ‘categoria’, width: 200 },
{ text: ‘Precio’, datafield: ‘precio’, width: 200 },
{ text: ‘Descripcion’, datafield: ‘descripcion’, width: 200 }
]
});
$(“#deletebutton”).jqxButton({ theme: theme });
// delete row.
$(“#deletebutton”).on(‘click’, function () {
var selectedrowindex = $(“#jqxgrid”).jqxGrid(‘getselectedrowindex’);
var rowscount = $(“#jqxgrid”).jqxGrid(‘getdatainformation’).rowscount;
if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
var commit = $("#jqxgrid").jqxGrid('deleterow', id);
}
});
});data_comercio.php
$row[‘nombre’],
‘categoria’ => $row[‘categoria’],
‘precio’ => $row[‘precio’],
‘descripcion’ => $row[‘descripcion’]);
}$data[] = array(
‘TotalRows’ => $total_rows,
‘Rows’ => $employees
);
echo json_encode($data);
}
?> -
AuthorPosts