I am filling a grid of JQWIDGETS with data from an array that I form from data entered in inputs text (code, description, price, quantity and total).
By giving enter on the input quantity the data is shown in the grid, but this creates an array every time I do this.
How can I make a new record in the same array every time I fill the inputs and do not replace the contents of the grid each time?
Thanks
This is what I have:
$(document).keyup(function (e) {
if ($("#txtCantServ").is(":focus") && (e.keyCode == 13)) {
var cant = $('#txtCantServ').val();
var punit = $('#txtprecio').val();
if (cant > 0) {
$('#txtCantServ').val('');
var codigo = $('#txtcodserv').val();
var nombre = $('#txtNomServ').val();
var total = punit * cant;
var dataGrilla = new Array();
var codigos = [codigo];
var nombres = [nombre];
var cantidades = [cant];
var precios = [punit];
var totales = [total];
for (var i = 0; i < 1; i++) {
var row = {};
row["colcodigos"] = codigos;
row["colnombres"] = nombres;
row["colcantidades"] = cantidades;
row["colprecios"] = precios;
row["coltotales"] = totales;
dataGrilla[i] = row;
}
console.log(dataGrilla);
var source =
{
localdata: dataGrilla,
datatype: "array"
};
$("#jqxgrid").jqxGrid(
{
width: 900,
source: source,
height: 200,
columns: [
{ text: 'CODIGO', datafield: 'colcodigos', width: 100 },
{ text: 'DESCRIPCION', datafield: 'colnombres', cellsformat: 'D',width: 500 },
{ text: 'CANTIDAD', datafield: 'colcantidades', width: 80 },
{ text: 'PRECIO', datafield: 'colprecios', width: 80, cellsalign: 'right' },
{ text: 'TOTAL', datafield: 'coltotales', width: 100, cellsalign: 'right', cellsformat: 'c2' },
]
});
}else{
alert('Ingrese cantidad.');
}
}
});