0

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.

user1668899
  • 1
  • 1
  • 2
  • My suggestion is that you can read values of the datagrid rows and create an xml string in javascript/jquery and pass it as parameter to an Ajax call which in turn will save the data into database. Also, you can access the rows collection from column object and save it using Ajax again. – Shant Nov 17 '12 at 16:44

1 Answers1

0

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

ramsuarez
  • 1
  • 1