jQWidgets Forums
jQuery UI Widgets › Forums › Grid › jqx.dataAdapter records.length
Tagged: data adapter, datagrid, datagrid control, jquery datagrid
This topic contains 1 reply, has 2 voices, and was last updated by support 13 years ago.
-
Author
-
In this code sample below, the var length = records.length; statement is returning 0 even if there are records return from the json call. Here is the returned stream from my json call:
[{“id”:1,”firstName”:”John”,”lastName”:”Smith”},{“id”:2,”firstName”:”Jane”,”lastName”:”Adams”},{“id”:3,”firstName”:”Jeff”,”lastName”:”Mayer”}]
Not sure how to get the real record count????
url = ‘http://localhost:8080/cyclone/user/ajax/list’;
var source = { datatype: “json”,
datafields: [
{ name: ‘id’,type: ‘int’ },
{ name: ‘firstName’ },
{ name: ‘lastName’ },
],
id: ‘id’,
url: url
}var dataAdapter = new $.jqx.dataAdapter(source,
{
downloadComplete: function ()
{
alert(“downloadComplete”);
// get data records.
var records = dataAdapter.records;
var length = records.length;
alert(“records.length = ” + length);
},
//loadComplete: function () {alert(“loadComplete”); },
// load error called on:
// ->bad url
loadError: function () {alert(“loadError”); }
});// initialize jqxGrid
$(“#jqxgrid”).jqxGrid(
{
width: 290,
source: dataAdapter,
pageable: false,
theme: theme,
altrows: true,
columnsresize: true,
autoheight: true,
enablehover: false,
columns: [
{ text: ‘Id’, datafield: ‘id’, width: 50 },
{ text: ‘First Name’, datafield: ‘firstName’, width: 120 },
{ text: ‘Last Name’, datafield: ‘lastName’, width: 120 }
]
});Hi ehoffman62,
The downloadComplete is called when the data is loaded from the remote data source. However, at that point, the data is still not loaded and the records will return 0. To ensure that the data is loaded and records is filled with items, you need to use the loadComplete callback instead.
var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function () { var length = dataAdapter.records.length; } });
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.