0

When page load, how to expand child nodes in devExtreme dxTreeview control by default. Please give some suggestions or examples.

Wayne Ellery
  • 7,888
  • 1
  • 28
  • 45
ipln
  • 113
  • 1
  • 2
  • 14

3 Answers3

0

Try to trigger a click on each trigger:

$( document ).ready( function(){
    $( '.dx-treeview-toggle-item-visibility' ).each( function(){
        $( this ).click();
    } );
} );
Mephiztopheles
  • 2,228
  • 1
  • 12
  • 25
  • Thanks for your quick reply. It's work fine on single level expanded tree node. But i need nested tree expanded (2 or 3 level). – ipln Jan 12 '15 at 12:56
  • do you have a fiddle for me, so i can try around? I think my solution just needs a little addition, but I don't know what – Mephiztopheles Jan 12 '15 at 12:58
0

You could try a recursive approach:

// Declare a function
var clickRecursive = function ($elements, selector) {
  // Exit recursion
  if ($elements.length === 0) return;

  $elements.each(function(){
    // First, click all elements
    $(this).click();

    // Then click children
    clickRecursive($(this).find(selector), selector);
  });
}

$(document).ready(function(){
  var toggleSelector = '.dx-treeview-toggle-item-visibility';
  clickRecursive($(toggleSelector), toggleSelector);
});
Guilherme Rodrigues
  • 2,818
  • 1
  • 17
  • 22
0

You can use expandedExpr option. It specifies the name of the data source item field whose value defines whether or not the corresponding node is expanded. For example, you could init dxTreeView something like this:

$("#your-selector").dxTreeView({
   dataSource: [
        id: 1, text: 'Item 1', expanded: true, items: [
            id: 2, text: 'Subitem 1', expanded: true, items: [
              //...
            ]
        ]
   ]
});

Also you can use expandItem(itemElement) method to expand some particular node.

See more information here http://js.devexpress.com/Documentation/ApiReference/UI_Widgets/dxTreeView

Sergey
  • 5,396
  • 3
  • 26
  • 38