Expand and Collapse Tree Grid

Hi,

I have two buttons, one to expand my tree grid row and one to collapse my tree grid row.
Both buttons don't work and everytime I click on either one I get this error:

"Line: 228
Error: The value of the property 'traverseTree' is null or undefined, not a Function object"

I am not sure what is wrong with it.

This is what i have and thank you for helping me :-)

//my two buttons
<input type="button" value="Expand" id='ExpandAllButton' name="ExpandAllButton" />
<input type="button" value="Collapse" id='CollapseAllButton' name="CollapseAllButton" />

    <script type="text/javascript">
        $(document).ready(function () {          

          $("#ExpandAllButton").jqxButton({});
           $('#ExpandAllButton').click(function () {
               expandAllTreeGrid("treeGrid");
           });

           $("#CollapseAllButton").jqxButton({});
           $('#CollapseAllButton').click(function () {
                collapseAllTreeGrid("treeGrid");
           });


});


// These methods receive the id of the treeGrid to work with.
            function expandAllTreeGrid(treeGridId) {
               traverseTreeGrid(treeGridId,"expand");
            }
			
            function collapseAllTreeGrid(treeGridId) {
               traverseTreeGrid(treeGridId,"collapse");
            }
 
            function traverseTreeGrid(treeGridId, action) {
               var treeGrid = "$(\"#" + treeGridId + "\")";
               var rows = eval(treeGrid).jqxTreeGrid('getRows');
                for(var i = 0; i < rows.length; i++) {
                    if (rows[i].records) {
                        if (action == "expand") {
                           eval(treeGrid).jqxTreeGrid('expandRow',rows[i].rowId);
                        } else if (action == "collapse") {
                           eval(treeGrid).jqxTreeGrid('collapseRow',rows[i].rowId);
                        }
                        traverseTree(rows[i].records);
                    }
                }
            };


</script>

Open in new window

lulu50Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
On line 41, you are calling:
traverseTree(rows[ i ].records);

Where is your function traverseTree(...){...} definition?
0
lulu50Author Commented:
Hielo,

my function is here

where would I put it !!!!

    function traverseRows(rows) {
      var idValue;
      for(var i = 0; i < rows.length; i++) {
        if (rows[i].records) {
          idValue = rows[i][idColumn];
          treeGrid.jqxTreeGrid(action+'Row',idValue);
          traverseRows(rows[i].records);
        };
      };
    };

    var idColumn = treeGrid.jqxTreeGrid('source')._source.id;
    traverseRows(treeGrid.jqxTreeGrid('getRows'));

Open in new window

0
lulu50Author Commented:
lol
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

lulu50Author Commented:
0
lulu50Author Commented:
<!DOCTYPE html>
<html lang="en">
<head>
    <title id="Description">Blaze Rule.</title>
    <link rel="stylesheet" href="CSS/jqx.base.css" type="text/css" />
      
    <script type="text/javascript" src="Script/Grid/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxcore.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxdata.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxdata.export.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxbuttons.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxscrollbar.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxdatatable.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxtreegrid.js"></script> 
    <script type="text/javascript" src="Script/Grid/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="Script/Grid/jqxlistbox.js"></script>
    <script type="text/javascript" src="Script/Grid/demos.js"></script>
    

    <script type="text/javascript">
        $(document).ready(function () {          

			$("#ExpandAllButton").jqxButton({});
           $('#ExpandAllButton').click(function () {
               expandAllTreeGrid("treeGrid");
           });

			$("#CollapseAllButton").jqxButton({});
           $('#CollapseAllButton').click(function () {
                collapseAllTreeGrid("treeGrid");
           });


		    // prepare the data
            var source =
            {
                dataType: "csv",
                dataFields: [
                    { name: 'EmployeeKey', type: 'number' },
                    { name: 'ParentEmployeeKey', type: 'number' },
                    { name: 'FirstName', type: 'string' },
                    { name: 'LastName', type: 'string' },
                    { name: 'Title', type: 'string' },
                    { name: 'HireDate', type: 'date' },
                    { name: 'BirthDate', type: 'date' },
                    { name: 'Phone', type: 'string' },
                    { name: 'Gender', type: 'string' },
                    { name: 'DepartmentName', type: 'string' }
                ],
                hierarchy:
                {
                    keyDataField: { name: 'EmployeeKey' },
                    parentDataField: { name: 'ParentEmployeeKey' }
                },
                id: 'EmployeeKey',
                url: 'employeesadv.csv'
            };
            var dataAdapter = new $.jqx.dataAdapter(source);
            // create Tree Grid
            $("#treeGrid").jqxTreeGrid(
            { 
			  
			    width: 850,
                source: dataAdapter,
                pageable: true,
                columnsResize: true,
				sortable: true,
				filterable: true,                
			    filterMode: 'simple',
				
				pagerMode: 'advanced',                
			    pageSizeMode: 'root',                
			    pageSize: 10, 
				pageSizeOptions: ['2', '3', '4', '5', '6', '7', '8', '9', '10'],   
				
                ready: function()
                {	
                    $("#treeGrid").jqxTreeGrid('expandRow', 32);
                },
                columns: [
                  { text: 'FirstName', dataField: 'FirstName', minWidth: 100, width: 200 },
                  { text: 'LastName',  dataField: 'LastName', width: 200 },
                  { text: 'Department Name', dataField: 'DepartmentName', width: 150 },
                  { text: 'Title', dataField: 'Title', width: 300 },
                  { text: 'Birth Date', dataField: 'BirthDate', cellsFormat: 'd', width: 120 },
                  { text: 'Hire Date', dataField: 'HireDate', cellsFormat: 'd', width: 120 },
                  { text: 'Phone', dataField: 'Phone', cellsFormat: 'd', width: 120 }
                ]
            });
			
	
				// Export data			
				$("#excelExport").jqxButton();
				$("#excelExport").click(function () {
				var rows = $("#treeGrid").jqxTreeGrid('getRows');
                    for (var i = 0; i < rows.length; i++) {
                        var key = $("#treeGrid").jqxTreeGrid('getKey', rows[i]);
                        $("#treeGrid").jqxTreeGrid('expandRow', key);
                    }
				$("#treeGrid").jqxTreeGrid('exportData', 'xls');
				});
       });
		


            // These methods receive the id of the treeGrid to work with.
            function expandAllTreeGrid(treeGridId) {
               traverseTreeGrid(treeGridId,"expand");
            }
			
			 function collapseAllTreeGrid(treeGridId) {
               traverseTreeGrid(treeGridId,"collapse");
            }
 
       function traverseTreeGrid(treeGridId, action) {
				var idValue;
               var treeGrid = "$(\"#" + treeGridId + "\")";
               var rows = eval(treeGrid).jqxTreeGrid('getRows');
                for(var i = 0; i < rows.length; i++) {
                    if (rows[i].records) {
                        if (action == "expand") {
                           eval(treeGrid).jqxTreeGrid('expandRow',rows[i].rowId);
                        } else if (action == "collapse") {
                           eval(treeGrid).jqxTreeGrid('collapseRow',rows[i].rowId);
                        }
                        traverseTree(rows[i].records);
                    }
                }
				
				
		// Traverse tree grid to do a full "expand" or "collapse"		
		    function traverseRows(rows) {
      		var idValue;
      			for(var i = 0; i < rows.length; i++) {
        			if (rows[i].records) {
          				idValue = rows[i][idColumn];
          				treeGrid.jqxTreeGrid(action+'Row',idValue);
          				traverseRows(rows[i].records);
        			};
      			};
    		};

    		var idColumn = treeGrid.jqxTreeGrid('source')._source.id;
    		traverseRows(treeGrid.jqxTreeGrid('getRows'));		

       };


    </script>
</head>
<body class='default'>
<div id="treeGrid"></div>
<div style='margin-top: 20px;'>
<div style='float: left;'>
<input type="button" value="Export to Excel" id='excelExport' />

<input type="button" value="Expand" id='ExpandAllButton' name="ExpandAllButton" />
<input type="button" value="Collapse" id='CollapseAllButton' name="CollapseAllButton" />

   
</div>

</div>



</body>
</html>

Open in new window

0
lulu50Author Commented:
I'm getting this error

Line: 229
Error: The value of the property 'traverseTree' is null or undefined, not a Function object
0
hieloCommented:
>> I got the code from this link
The last post on the link you provided has two implementations for function traverseTreeGrid().  Try using the last one instead.
0
lulu50Author Commented:
I'm trying but can't get it to work

this function works it will expand only the second the first child folder but I want all to be expanded.

How can I change it to expand all it work with just Parent, First child but i want all to be expanded.


			// Export data			
				$("#excelExport").jqxButton();
				$("#excelExport").click(function () {
				var rows = $("#treeGrid").jqxTreeGrid('getRows');
                    for (var i = 0; i < rows.length; i++) {
                        var key = $("#treeGrid").jqxTreeGrid('getKey', rows[i]);
                        $("#treeGrid").jqxTreeGrid('expandRow', key);
                    }
				$("#treeGrid").jqxTreeGrid('exportData', 'xls');
				});

Open in new window

0
lulu50Author Commented:
Hielo,

can you believe this simple code did it for me.

$("#treeGrid").jqxTreeGrid('collapseAll')
$("#treeGrid").jqxTreeGrid('expandAll')

that's it!!!!!

there is a built in function for expandAll and collapseAll

Thanks,
Lulu
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hieloCommented:
:) Glad you were able to figure it out.
0
lulu50Author Commented:
I found the solution to my question

$("#treeGrid").jqxTreeGrid('collapseAll')
 $("#treeGrid").jqxTreeGrid('expandAll')
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.