jQuery UI Widgets Forums Plugins Data Adapter DataAdapter records from localdata source

This topic contains 5 replies, has 2 voices, and was last updated by  Peter Stoev 9 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • DataAdapter records from localdata source #75389

    ziggy
    Participant

    Hi,

    Why do I get the following error when I try to get a record from dataAdapter?

    Cannot read property 'records' of undefined

    Here’s my code:

    var dataAdapter= new $.jqx.dataAdapter(source,
                    {
                       
                            async: true,
                            autoBind: true,
                            loadComplete: function (records) {
                                 dataAdapter.records[0];

    Thanks!

    Karen

    DataAdapter records from localdata source #75396

    Peter Stoev
    Keymaster

    Hi Karen,

    Obviously, because the dataAdapter instance is undefined on the place you try to access it.

    Regards,
    Peter

    DataAdapter records from localdata source #75425

    ziggy
    Participant

    Hi Peter,

    What do you mean by “instance is undefined”? As you can see in my code, I have defined it.

    var dataAdapter= new $.jqx.dataAdapter(source,
    {

    async: true,
    autoBind: true,
    loadComplete: function (records) {
    dataAdapter.records[0];

    My concern is I cannot get the records when I am using a localdata as source. I have tried it with a remote source (url) and it worked.

    Regards,
    Karen

    DataAdapter records from localdata source #75438

    Peter Stoev
    Keymaster

    Hi Karen,

    I wrote you by email earlier and I do not understand why we discuss same things on several places. Anyway, The problem is that you’re trying to use an instance in its definition so it is undefined there. Also the “records” parameter in the loadComplete function contains the dataAdapter’s records.

    Regards,
    Peter

    DataAdapter records from localdata source #75455

    ziggy
    Participant

    Hi Peter,

    Just in case some users may encounter the same problem, I might as well share it in this forum.

    Also, as mentioned in my email, I’ve been using the one same as the demo sample from
    Demo dataAdapter bindingtojson:

    var dataAdapter = new $.jqx.dataAdapter(source, {
                    loadComplete: function (records) {
                        // get data records.
                        var records = dataAdapter.records;
                        // get the length of the records array.
                        var length = records.length;
                        // loop through the records and display them in a table.
                        var html = "<table border='1'><tr><th align='left'>Name</th><th align='left'>Type</th><th align='left'>Calories</th><th align='right'>Total Fat</th><th align='left'>Protein</th></tr>";
                        for (var i = 0; i < 20; i++) {
                            var record = records[i];
                            html += "<tr>";
                            html += "<td>" + record.name + "</td>";
                            html += "<td>" + record.type + "</td>";
                            html += "<td>" + record.calories + "</td>";
                            html += "<td>" + record.totalfat + "</td>";
                            html += "<td>" + record.protein + "</td>";
                            html += "</tr>";
                        }
                        html += "</table>";
                        $("#table").html(html);
                    },
                    loadError: function (jqXHR, status, error) {
                    },
                    beforeLoadComplete: function (records) {
                    }
                });

    …except that I am using a localdata as source. I get the undefined error when using the localdata as source.

    Hope I have explained this issue well.

    DataAdapter records from localdata source #75456

    Peter Stoev
    Keymaster

    Hi Karen,

    I think that my explainations so far are useless. See http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdataadapter/jquery-data-adapter.htm. There are samples how to bind to local data and remote data and the samples use the current version of jQWidgets. Hope the examples will help you to understand how to use this plugin.

    Regards,
    Peter

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.