jQuery UI Widgets › Forums › Navigation › Tree › Wrong ID in jqxTree
Tagged: jqxtree ID
This topic contains 3 replies, has 2 voices, and was last updated by Martin 5 years, 4 months ago.
-
AuthorWrong ID in jqxTree Posts
-
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 selectedvar 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);
});}
}});
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,
MartinjQWidgets Team
http://www.jqwidgets.com/is there an example for getting data via ajax
Hello Kyvaldenius,
Yes, you can see our demo about Loading jqxTree with ajax.
Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.