jQWidgets Forums

jQuery UI Widgets Forums Grid Multiple Roots in dataadapter

This topic contains 3 replies, has 2 voices, and was last updated by  Hristo 7 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Multiple Roots in dataadapter #97682

    bluesand4
    Participant

    Hi,
    In my dataadapter I am calling a remote web service that returns JSON data. The data format is like this:
    {“general”:{}, “records”:[{}, {}, …]}

    I want to bind the data in the general element with a datatable and the records with a grid. If I say root: ‘general’, then the data table works fine but not the grid, and vice versa.

    How to achieve my goal?

    Thanks

    Multiple Roots in dataadapter #97719

    Hristo
    Participant

    Hello bluesand4,

    You could use different DataAdapters and also, it is recommended to do when using different widgets.
    I would like to suggest you look at the demos grouped as “Data Binding”. Please, take a look at this demo:
    https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/bindingtoxml.htm?light

    If you have nested records it will be better to think about another widget.
    Please, take a look at this jqxTreeGrid demo: https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxtreegrid/javascript-tree-grid-binding-to-nested-json.htm?light

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    Multiple Roots in dataadapter #97739

    bluesand4
    Participant

    Hi,

    But using another data adapter means doing the same HTTP call again, whereas I have already received the data in the first call.

    Isn’t there a better option?

    Multiple Roots in dataadapter #97746

    Hristo
    Participant

    Hello bluesand4,

    You mentioned two widgets and for that reason the correct way is to use two DataAdapters.
    If you can get the data with one request to the base you could get the data with AJAX and after that to set it with different DataAdapters to each one widget.
    Also, I would like to suggest you try to use the mapping in the determinate different level of records of the data in the DataAdapter.
    Please, take a look at this example:

    var data = [
        {
            "state": {
                "id": "x526",
                "city": {
                    "name": "Beverly Hills",
                    "id": 90210,
                    "value": "Beverly Hills"
                }
            }
        }
    ];
    var source = {
        datatype: 'json',
        localdata: data,
        datafields:
        [
            {
                name: 'cityName', map: 'state>city>name'
            }
        ]
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.