I have a easyUI datagrid with several rows and I want to insert these rows into a database table.How can I do this.
NB:am using datagrid not editable datagrid.
I have a easyUI datagrid with several rows and I want to insert these rows into a database table.How can I do this.
NB:am using datagrid not editable datagrid.
Hi I have one solution like that you need, first you must store the data into String or Array and after send this to your script that save this into Database, check this code.
/* Array to store datagrid records /*
var facturas = {
lineas:[]
};
linea_facturas="";
//Armado del arreglo JSON a enviar
rows = $('#dg').datagrid('getRows'); // get all rows of Datagrid
for(var i=0; i<rows.length; i++){
var renglon = rows[i];
facturas.lineas.push({
"id_header" : $("#idheader").val() ,
"fecha_cr" : $('#dd').datebox('getValue') ,
"contrato" : renglon.id_contrato ,
"factura" : renglon.id_factura ,
"importe" : renglon.importe ,
"iva" : renglon.iva ,
"total" : renglon.total
});
linea_facturas =
linea_facturas +
$("#idheader").val() + "," +
$('#dd').datebox('getValue')+ ","+
renglon.id_contrato + "," +
renglon.id_factura + "," +
renglon.importe + "," +
renglon.iva + "," +
renglon.total + "&" ;
}
//var jsonText = JSON.stringify(facturas); //Convierte un valor de JavaScript en una cadena de la notación de objetos JavaScript (JSON).
//$.messager.alert('Info',linea_facturas);
//window.console.log(linea_facturas);
$.ajax({
type: "POST",
url: "Lector?action=SAVEDETAILS",
data: {registros :linea_facturas},
dataType: "json",
success: function(jsondata){
//$.messager.alert("Almacenado de detalles exitoso y se insertaron " + jsondata.detalle + " registros");
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
},
complete: function() { EnviaDatos(2); }
});
URL in POST must be your program that save the data, you must parse the data in the server side