Hi there!
Can you help me with this error: JavaScript runtime error: Object doesn't support property or method 'slice'
Two or more records are showed fine, but if just 1 records I got the message error and this code this.data=j.data.slice(l,i)
I'm using PQGrid 1.1.3
Portion of code:
Javascrit:
$.ajax({
type: 'POST',
url: 'contarcre.aspx/Consumos',
data: JSON.stringify({ filtro: filtros, th_dc: _th_dc }),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
beforeSend: function () { $('#divEspere').css('display', 'block'); },
complete: function () { $('#divEspere').css('display', 'none'); },
success: function (response) {
if (response.d != "") {
var Tarjeta = JSON.parse(response.d);
var consumos = Tarjeta.Registros.Consumos;
if (consumos) {
if (created) { $("#grid").pqGrid("destroy"); }
var obj = {};
obj.width = ($(window).width() - 320);
obj.height = 500;
obj.title = "Consumos";
obj.resizable = false;
obj.freezeCols = _th_dc == 'th' ? 2 : 5;
obj.draggable = false;
obj.selectionModel = { type: 'row' };
obj.scrollModel = { horizontal: _th_dc == 'th' ? false : true };
obj.numberCell = false;
obj.paging = true;
obj.columnBorders = true;
obj.editable = false;
if (_th_dc == 'th') {
//Tarjetahabiente
{
obj.colModel = [{ title: "Ciudad / País", width: 200, dataType: "string", dataIndx: 'CIUDAD_PAIS_COMERCIO' },
{ title: "Tipo Transacción", width: 110, dataType: "string", dataIndx: 'TIPO_CONSUMO' },
{ title: "Moneda", width: 80, dataType: "string", dataIndx: 'MONEDA', align: "center" },
{ title: "Establecimiento", width: 200, dataType: "string", dataIndx: 'ESTABLECIMIENTO' },
{ title: "Fecha de Consumo", width: 80, dataType: "string", dataIndx: 'FECHA_CONSUMO', align: "center" },
{ title: "Habitos de Consumo", width: 190, dataType: "string", dataIndx: 'TIPO_COMERCIO' },
{ title: "Monto", width: 110, dataType: "float", dataIndx: 'MONTO', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } }];
}
}
else if (_th_dc == 'dc') {
//Departamento de Credito
{
obj.colModel = [{ title: "Ciudad / País", width: 160, dataType: "string", dataIndx: 'CIUDAD_PAIS_COMERCIO' },
{ title: "Tipo Transacción", width: 80, dataType: "string", dataIndx: 'TIPO_TRANSACCION' },
{ title: "Moneda", width: 60, dataType: "string", dataIndx: 'MONEDA', align: "center" },
{ title: "Establecimiento", width: 200, dataType: "string", dataIndx: 'ESTABLECIMIENTO' },
{ title: "Fecha de Consumo", width: 80, dataType: "string", dataIndx: 'FECHA_CONSUMO', align: "center" },
{ title: "Luz / Agua / Telecomunicación", width: 110, dataType: "float", dataIndx: 'LUZ_AGUA_TELECOMUNICACIONES', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Supermercados", width: 96, dataType: "float", dataIndx: 'SUPERMERCADOS', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Transporte", width: 96, dataType: "float", dataIndx: 'TRANSPORTE', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Restaurantes y Afines", width: 100, dataType: "float", dataIndx: 'RESTAURANTES_AFINES', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Salud", width: 96, dataType: "float", dataIndx: 'SALUD', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Tiendas", width: 96, dataType: "float", dataIndx: 'TIENDAS', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Estudios / Cultura", width: 96, dataType: "float", dataIndx: 'ESTUDIOS_CULTURA', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Entretenimiento", width: 96, dataType: "float", dataIndx: 'ENTRETENIMIENTO', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Pagos", width: 96, dataType: "float", dataIndx: 'PAGOS', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Avance Efectivo", width: 96, dataType: "float", dataIndx: 'AVANCE_EFECTIVO', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Avance Línea", width: 96, dataType: "float", dataIndx: 'AVANCE_LINEA', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } },
{ title: "Otros", width: 96, dataType: "float", dataIndx: 'OTROS', align: "right", render: function (ui) { var cV = ui.rowData[this.dataIndx]; return cV == '-' ? cV : accounting.formatNumber(cV, 2); } }];
}
}
obj.dataModel = {
data: consumos,
location: "local",
paging: "local",
curPage: 1,
rPP: 20,
rPPOptions: [10, 20, 30, 40, 50, 100, 500, 1000]
}
$("#grid").pqGrid(obj);
$("#grid").pqGrid("refresh");
$("#grid").pqGrid("option", "roundCorners", true);
$("#grid").pqGrid("option", $.paramquery.pqGrid.regional['es']);
$("#grid").find(".pq-pager").pqPager("option", $.paramquery.pqPager.regional['es']);
created = true;
$('#tblCliente').css('display', 'block');
$('#btnDatos').css('display', 'none');
$('#btnGrafico').button({
icons: { primary: 'ui-icon-image' },
text: true
}).css('display', 'block').click(function (event) {
$('#grid').css('display', 'none');
$('#divGraficos').css('display', 'block');
$('#btnGrafico').css('display', 'none');
$('#btnDatos').css('display', 'block');
ver_grafico();
});
}
}
else {
if (created) { $("#grid").pqGrid("destroy"); }
$('#tblCliente').css('display', 'none');
$('#divGraficos').css('display', 'none');
$('#divGridCliente').html('').css('display', 'none');
$('#divEspere').css('display', 'none');
created = false;
alert('No existen datos para mostrar...');
}
},
failure: function (response) { alert(response.d); },
//error: function (response) { alert(response.d); }
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
C#:
I got the json string through this:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(ds.GetXml());
json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented);
Thanks!!!