jQuery UI Widgets › Forums › Grid › DropDown Tree in Grid
Tagged: column, columntype, createeditor, custom, dropdown tree, dropdownbutton, editor, geteditorvalue, grid, initeditor, jqxDropDownButton, jqxgrid, jqxtree, Tree
This topic contains 12 replies, has 2 voices, and was last updated by Dimitar 11 years ago.
-
AuthorDropDown Tree in Grid Posts
-
Hi, how can i make a DropDownTree in Grid?
Hello simcon94,
You can achieve this by using custom editors, as shown in the demos Custom Column Editor and Custom Row Editor.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/But there is only a dropdownList.
No DropDownTreethat must be something like this:
text: ‘Test’, columntype: ‘jqxDropDownButton’, displayfield: “Test”, datafield: “TestId”, width: 200,
createeditor: function (row, cellvalue, editor, cellText, width, height) {
$(‘#ParentNodesTree’).jqxTree({ source: dataAdapter});
$(‘#ParentNodesTree’).on(‘select’, function (event) {
var args = event.args;
var item = $(‘#ParentNodesTree’).jqxTree(‘getItem’, args.element);
var topologyId = item.id;
editor.jqxDropDownButton(‘setContent’, item.label);
editor.jqxDropDownButton(‘close’);
});
$(‘#ParentNodesTree’).jqxTree(‘expandAll’);
editor.jqxDropDownButton({ width: ‘250’, height: ’25px’ });
}Hi simcon94,
Instead of ‘jqxDropDownButton’ use
columntype: 'custom'
. You can learn more about columntype in the jqxGrid API Documentation.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Do you have a example?
Thats my Code now:
`createeditor: function (row, cellvalue, editor, cellText, width, height) {//editor.empty();
editor.append(‘<div id=”dropDownTreeId”><div style=”border: none;” id=”ParentNodesTree”></div></div>’);var records = sk.tree.getTopologyTree(“GetTree”);
$(“#dropDownTreeId”).jqxDropDownButton({ width: 200, height: ’25px’ });
$(‘#ParentNodesTree’).jqxTree({ source: records });
$(‘#ParentNodesTree’).jqxTree(‘expandAll’);$(‘#ParentNodesTree’).on(‘select’, function (event) {
var args = event.args;
var item = $(‘#ParentNodesTree’).jqxTree(‘getItem’, args.element);
var dropDownContent = ‘<div style=”position: relative; margin-left: 3px; margin-top: 5px;”>’ + item.label + ‘</div>’;
$(“#dropDownTreeId”).jqxDropDownButton(‘setContent’, dropDownContent);
$(“#dropDownTreeId”).jqxDropDownButton(‘close’);editor.jqxDropDownButton(‘setContent’, item.label);
//editor.append(‘<div id=”dropDownTreeId”><div style=”border: none;” id=”ParentNodesTree”>’ + item.label + ‘</div></div>’);
});
$(“#dropDownTreeId”).jqxDropDownButton({ width: 200, height: ’25px’ });
}`That works so long, till i click in another cell in Grid. Then the Cell is empty….
Hi simcon94,
Here is how to initialize the dropdown tree:
columns: [ { text: 'Ship City', datafield: 'ShipCity', width: 150, columntype: 'custom', createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) { editor.append("<div class='jqxTree' style='width: " + (cellwidth - 2) + "px;'><ul><li>Item 1</li><li>Item 2</li></ul></div>"); editor.jqxDropDownButton(); $(".jqxTree").jqxTree(); } },
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thats no tree
The tree in my example is ok. But the seleted item will not be shown in the Grid….
Hi simcon94,
Here is a modification of the code, with more tree items and geteditorvalue set to return the selection of the tree. Note the tree’s id is now set:
columns: [ { text: 'Ship City', datafield: 'ShipCity', width: 150, columntype: 'custom', createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) { editor.append("<div id='" + editor[0].id + "Tree' class='jqxTree' style='width: " + (cellwidth - 2) + "px;'><ul><li>Item 1</li><li>Item 2<ul><li>Item 2.1</li><li>Item 2.2</li></ul></li></ul></div>"); editor.jqxDropDownButton(); $(".jqxTree").jqxTree(); }, geteditorvalue: function (row, cellvalue, editor) { var tree = $("#" + editor[0].id + "Tree"); var selection = tree.jqxTree('getSelectedItem'); return selection.label; } },
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/I tried it this way:
createeditor: function (row, cellvalue, editor, cellText, width, height) { editor.append("<div id='" + editor[0].id + "Tree' class='jqxTree' style=''><div style='border: none;' id='ParentNodesTree'></div></div>"); var records = sk.tree.getTopologyTree("/GetTree"); $(".jqxTree").jqxDropDownButton({ width: 200, height: '25px' }); $("#ParentNodesTree").jqxTree({ source: records }); $("#ParentNodesTree").jqxTree('expandAll'); $("#ParentNodesTree").on("select", function (event) { var args = event.args; var item = $("#ParentNodesTree").jqxTree('getItem', args.element); var dropDownContent = '<div style="position: relative; margin-left: 3px; margin-top: 5px;">' + item.label + '</div>'; $(".jqxTree").jqxDropDownButton('setContent', dropDownContent); $(".jqxTree").jqxDropDownButton('close'); editor.jqxDropDownButton('setContent', item.label); }); } ,geteditorvalue: function (row, cellvalue, editor) { var tree = $("#" + editor[0].id + "Tree"); var selection = tree.jqxTree('getSelectedItem'); console.log(selection.label); return selection.label; }
but i still have error:
TypeError: selection is undefinedHi simcon94,
That is because you most probably did not select an item from the tree. You should check if the selection is defined:
geteditorvalue: function (row, cellvalue, editor) { var tree = $("#" + editor[0].id + "Tree"); var selection = tree.jqxTree('getSelectedItem'); if (selection) { console.log(selection.label); return selection.label; } else { return ""; }; }
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.