var data = [
{
"id": "child1",
"parentid": "parent",
"text": "BandWidth",
"desc": "This report displays events on the sources along with event code, severity and description.",
"custom": 'Alternatively description'
},
{
"id": "child2",
"parentid": "parent",
"text": "Bonus BandWidth",
"desc": "Bonus description about it.",
"custom": 'Alternatively description - Bonus'
},
{
"id": "parent",
"parentid": "-1",
"text": "Device Based Reports"
},
];
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'id' },
{ name: 'parentid' },
{ name: 'text' },
//{ name: 'value', map: 'desc' },
{ name: 'desc' },
{ name: 'custom' }
],
id: 'id',
localdata: data
};
// create data adapter.
var dataAdapter = new $.jqx.dataAdapter(source);
// perform Data Binding.
dataAdapter.dataBind();
// get the tree items. The first parameter is the item's id. The second parameter is the parent item's id. The 'items' parameter represents
// the sub items collection name. Each jqxTree item has a 'label' property, but in the JSON data, we have a 'DisplayName' field. The last parameter
// specifies the mapping between the 'DisplayName' and 'label' fields.
var records = dataAdapter.getRecordsHierarchy('id', 'parentid', 'items', [{ name: 'text', map: 'label' }, { name: 'desc', map: 'value' }]);
console.log(records);
$('#jqxTree').jqxTree({
source: records,
width: '300px',
});
$('#jqxTree').on('select', function (event) {
var args = event.args;
var item = $('#jqxTree').jqxTree('getItem', args.element);
var label = item.label;
//var description = item.description;
var val = item.value;
console.log('value ' + val);
console.log(label);
//console.log(item.id);
var allRecords = dataAdapter.getrecords();
//console.log(allRecords);
for (var i = 0; i < allRecords.length; i++) {
if (allRecords[i].id === item.id) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.