To execute the example, in the HEAD tag add links to component library PP.js and visual style tables PP.css. Add the DIV item with the "container" identifier in the BODY tag.
Connect the script that generates random nodes:
<script src="genJsonDyn.js" type="text/javascript"></script>
Add the following code to the <script> tag:
// New node get function function onDataRequest(sender, args) { var nodes = {}; var node; if (args.Partial) for (var i = 0; i < args.Request.length; i++) { node = genNode(args.Request[i].Parent, args.Request[i].Index, count); nodes[node['k']] = node; } else {
for (var i = 0; i < count; i++) { node = genNode(args.Parent, i, count); nodes[node['k']] = node; } } PP.setTimeout(function () { // Simulate server response delay sender.loadNodes(nodes); // Load nodes }, 400); };
var count = 50; // Number of created nodes var json = []; json.push({ 'k': '', '@hc': true, '@cc': count }); // Create a component var t, treelist; t = treelist = new PP.Ui.DynamicTreeList({ ParentNode: 'container', DataObject: json, DataMappers: {
Key: 'k', Index: 'i', Parent: 'p', Content: new PP.PropertyMapper({ Getter: function (item) { return item.a.it }, Setter: function (item, value) { item.a.it = value; }, Context: null }), Selected: 's', FixedSelected: '@fs', Expanded: 'e',
ChildrenCount: '@cc' }, Width: 700, Height: 550, ShowCheckBoxes: true, EnableSort: true, ShowCaptions: true, ShowTree: true, Captions:
[{ Content: 'first', Width: '36%' },{ Content: 'second', Width: '11%' },{
Content: 'third', Width: '53%' } ], DataRequest: onDataRequest });
After executing the example the DynamicTreeList component is created. On opening the node new nodes are requested and dynamically added to tree.
See also: