jQuery UI Widgets Forums Navigation Tree Wrong ID in jqxTree

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  Martin 3 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Wrong ID in jqxTree #101006

    Kyvaldenius
    Participant

    Hi

    there was such problemma
    I call a tree with a load through ajax, I select a tree element.
    The selected element causes a load of child elements but problem
    in the fact that in the property
    var $ element = $ (event.args.element);
    IdParent: $ element [0] .id,

    $ element [0] .id = “jqxWidget084752dc”
    but should be the id of the item that was selected

    var tree = $(‘#TsrTree’);
    var idtree;
    var source = null;
    var search = $(‘#searchAddressObjectsName’);
    $.ajax({
    type: ‘GET’,
    url: ‘/Directorys/TSRSelect/’,
    contentType: ‘application/JSON’,
    complete: function (answer, status) {
    if (status == ‘success’) {
    source = {
    datatype: “json”,
    datafields: [
    { name: ‘IDRecord’ },
    { name: ‘IDSRecord’ },
    { name: ‘NameRecord’ }

    ],
    id: ‘IDRecord’,
    localdata: JSON.parse(answer.responseText)

    // answer.responseJSON
    // JSON.parse(answer.responseText)//.responseJSON
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    dataAdapter.dataBind();
    var records = dataAdapter.getRecordsHierarchy(‘IDRecord’, ‘IDSRecord’, ‘items’, [{ name: ‘NameRecord’, map: ‘label’ }]);
    tree.jqxTree({ source: records, width: ‘98%’, height: ‘200px’, theme: ‘fresh’ });
    records = tree.jqxTree(‘getItems’);
    for (var k = 0; k < records.length; ++k) {
    tree.jqxTree(‘addTo’, { label: ‘Загрузка…’ }, records[k]);
    }

    tree.on(‘expand’, function (event) {
    var label = tree.jqxTree(‘getItem’, event.args.element).label;
    var $element = $(event.args.element);
    // alert($element[0].id)
    var loader = false;
    var loaderItem = null;
    var children = $element.find(‘ul:first’).children();
    $.each(children, function () {
    var item = tree.jqxTree(‘getItem’, this);
    if (item && item.label == ‘Загрузка…’) {
    loaderItem = item;
    loader = true;
    return false;
    };
    });
    if (loader) {
    alert($element[0].id)

    $.ajax({
    type: ‘GET’,
    dataType: “json”,
    contentType: ‘application/JSON’,
    // data: JSON.stringify(datas),
    data: {
    IdParent: $element[0].id,
    Name: “”
    },
    url: ‘/Directorys/TSRSelect’,
    cache: false,
    complete: function (answer, status) {
    if (status == ‘success’) {
    var data = JSON.parse(answer.responseText);
    for (var k = 0; k < data.length; ++k) {
    data[k][“label”] = data[k].NameRecord;
    data[k][“leaf”] = true;
    data[k][“parent”] = $element[0].id;
    data[k][“uid”] = data[k].id;
    // data[k][“value”] = data[k].isLast;

    if (!data[k].isLast) {
    data[k][“items”] = { label: ‘Загрузка…’ };
    }
    }
    tree.jqxTree(‘addTo’, data, $element[0]);
    tree.jqxTree(‘removeItem’, loaderItem.element);
    }
    }
    });

    }

    });
    tree.on(‘select’, function (event) {
    var args = event.args;
    var item = tree.jqxTree(‘getItem’, args.element);
    tree.jqxTree(‘expandItem’, item);
    });

    }
    }

    });

    Wrong ID in jqxTree #101036

    Martin
    Participant

    Hello Kyvaldenius,

    You should set the id of the items to be able to get it after that, the same way you are setting their label.

    Each tree item in the source object may have the following fields:
    Item Fields
    label – sets the item’s label.
    value – sets the item’s value.
    html – item’s html. The html to be displayed in the item.
    id – sets the item’s id.
    disabled – sets whether the item is enabled/disabled.
    checked – sets whether the item is checked/unchecked(when checkboxes are enabled).
    expanded – sets whether the item is expanded or collapsed.
    selected – sets whether the item is selected.
    items – sets an array of sub items.
    icon – sets the item’s icon(url is expected).
    iconsize – sets the size of the item’s icon.

    Here is an Example on how you can get the jqxTree items’ ids.

    Best Regards,
    Martin

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

    Wrong ID in jqxTree #101037

    Kyvaldenius
    Participant

    is there an example for getting data via ajax

    Wrong ID in jqxTree #101065

    Martin
    Participant

    Hello Kyvaldenius,

    Yes, you can see our demo about Loading jqxTree with ajax.

    Best Regards,
    Martin

    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.