jQWidgets Forums

jQuery UI Widgets Forums Navigation Tree Populate Tree label?

This topic contains 11 replies, has 2 voices, and was last updated by  realtek 9 years, 8 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
  • Populate Tree label? #75628

    realtek
    Participant

    Hi,

    When you have a tree which is bound to a datasource how do you set which value is the label of the item in the tree?

    I am using a dataAdapter:

      var url = "api/form/Output";
                    // prepare the data
                    var source =
                            {
                                data: {
                                    Seq_Table: "18"
                                },
                                datatype: "json",
                                datafields: [
                                { name: 'DisplayName' },
                                { name: 'Seq' },
                                { name: 'Seq_BaseTable' }
    
                                ],
                                id: 'Seq',
                                url: url,
                                type: "POST",
                                async: true
                            };
                    var dataAdapter = new $.jqx.dataAdapter(source);
    
                    $("#tree").jqxTree({ width: 200, height: 220, checkboxes: true, source: dataAdapter });
    

    I am just seeing:

    Item
    Item
    Item
    Item

    Populate Tree label? #75636

    Vladimir
    Participant

    Hello realtek,

    The TreeGrid source functionality is explained in the demos in the API Reference section under source.
    You can find the full list of fields and how they need to be referenced there.
    You can use the dataAdapter map: functionality to map your own fields to the relevant value.

    Example:

                                { name: 'label' map: 'DisplayName'},
    

    Best Regards,
    Vladimir

    jQWidgets team
    http://www.jqwidgets.com/

    Populate Tree label? #75637

    realtek
    Participant

    Hi Vladimir,

    I did notice this and tried that several times but it made no difference.

    I have since realised this morning that the request is not happening to the server and no data is actually happening.

    Do you know why the above would not even try to call the web api?

    Everything else is working!

    Thanks

    Populate Tree label? #75640

    realtek
    Participant

    I have just sorted it now, I forgot the databind 🙂

    Populate Tree label? #75642

    realtek
    Participant

    The request is now working but using them method above still fails to map my data.

    The json response looks fine. I am getting too many tree items and they all just say ‘Item’

    Populate Tree label? #75647

    Vladimir
    Participant

    Hello realtek,

    Please try the method used in the binding to json demo.
    The mapping there is done in a records variable.

                    var records = dataAdapter.getRecordsHierarchy('id', 'parentid', 'items', [{ name: 'text', map: 'label'}]);
    

    Best Regards,
    Vladimir

    jQWidgets team
    http://www.jqwidgets.com/

    Populate Tree label? #75648

    realtek
    Participant

    I think the issue is that the dataAdapter is empty. I have checked the server response and I can see the json response coming back and it looks fine.

    Here is the json:

    [
    {
    “DisplayName”: “Sequence”,
    “Seq_Field”: “83”,
    “Seq_BaseTable”: “12”
    },
    {
    “DisplayName”: “Test ID”,
    “Seq_Field”: “84”,
    “Seq_BaseTable”: “12”
    },
    {
    “DisplayName”: “Duration”,
    “Seq_Field”: “85”,
    “Seq_BaseTable”: “12”
    },
    {
    “DisplayName”: “Person”,
    “Seq_Field”: “86”,
    “Seq_BaseTable”: “12”
    },
    {
    “DisplayName”: “Address”,
    “Seq_Field”: “87”,
    “Seq_BaseTable”: “12”
    }
    ]

    I have even tried displays dataAdapter.records.length inside the load complete of the dataAdapter but it returns 0 ?

    Populate Tree label? #75649

    realtek
    Participant

    ok, I do not know why but I have got it working with:

    .jqxTree({source: dataAdapter.records})

    Do you know what is causing this?

    Thanks

    Populate Tree label? #75650

    Vladimir
    Participant

    Hello realtek,

    Make sure you have called the dataAdapter.dataBind() method.
    Take a look at this sample with the json you provided.

    Best Regards,
    Vladimir

    jQWidgets team
    http://www.jqwidgets.com/

    Populate Tree label? #75652

    realtek
    Participant

    Hi,

    ok it is finally sorted. It was due to the timing of things, basically because I had async set to true it did not have time to populate the tree.

    Is that normal behaviour? Should the source be set in a bindingComplete or something?

    Populate Tree label? #75659

    Vladimir
    Participant

    Hello realtek,

    The Tree has no autobind functionality, so if the dataAdapter records get updated after the initialization, you need to reset the source manually.

    You can try to use loadComplete callback of the dataAdapter:

    
             loadComplete: function () {
                            $('#jqxTree').jqxTree({ source: dataAdapter.records});
                        },

    Best Regards,
    Vladimir

    jQWidgets team
    http://www.jqwidgets.com/

    Populate Tree label? #75688

    realtek
    Participant

    Thanks, this is now working!

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

You must be logged in to reply to this topic.