TreeGrid with DS

I am trying to setup my own treeGrid and reuse a XML DS on my site.

I have seen the examples on the site (http://www.smartclient.com/index.jsp#treeLoadXML). I have tried to combine multiple fragments from them to create something that uses a slightly different DS.

The page loads, the XML is fetched but the treeGrid does not display anything - it just says ‘Loading data…’

What do I need to change to make it work with my XML DS?

isc.DataSource.create({
	ID: "treeTestDS",
	dataProtocol: "getParams",
	fields:[
		{name: "sectionId", type:"text", canEdit: true}, 
		{name: "sectionName", type:"text", canEdit: true}, 
		{name: "parentId", type:"text", canEdit: true}
	]
	, dataFormat:"xml"
	, recordXPath:"/List/section"
	,dataURL:"?do=fetch"		
});

isc.VLayout.create({width:"100%",height:"100%",members: [
	isc.TreeGrid.create({
		ID: "treeTest",
		autoFetchData: true,
		dataSource: "treeTestDS",
		dataProperties: {
			modelType: "parent",
			rootValue: 0,
			nameProperty: "sectionName",
			idField: "sectionId",
			parentIdField: "parentId",
			openProperty: "isOpen",
			isFolderProperty:"isFolder"
		}
	})
]});
<List>
<section>
<sectionId>wxy</sectionId>
<sectionName>WXY</sectionName>
<parentId>root</parentId>
</section>
<section>
<sectionId>wxy1</sectionId>
<sectionName>WXY 1</sectionName>
<parentId>wxy</parentId>
</section>
<section>
<sectionId>wxy2</sectionId>
<sectionName>WXY 2</sectionName>
<parentId>wxy</parentId>
</section>
<section>
<sectionId>wxy3</sectionId>
<sectionName>WXY 3</sectionName>
<parentId>wxy</parentId>
</section>
<section>
<sectionId>wxy4</sectionId>
<sectionName>WXY 4</sectionName>
<parentId>wxy</parentId>
</section>
<section>
<sectionId>abc</sectionId>
<sectionName>ABC</sectionName>
<parentId>root</parentId>
</section>
<section>
<sectionId>abc1</sectionId>
<sectionName>ABC 1</sectionName>
<parentId>abc</parentId>
</section>
<section>
<sectionId>abc2</sectionId>
<sectionName>ABC 2</sectionName>
<parentId>abc</parentId>
</section>
</List>

Very close - you need to move a couple of settings to the DataSource level rather than trying to declare them in the individual TreeGrid.

The “parentId” field should have foreignKey:“sectionId”.

The “sectionId” field should have primaryKey:true, rootValue:“root”.

Only the openProperty and isFolderProperty settings remain in treeGrid.dataProperties.

Thank you I now have that working.

All items in the treeGrid have silver triangle indicating they can be expanded. This is the case for some and when they’re expanded the data is requested from the server and displayed correctly but is there anyway in the XML to indicate that the element won’t expand further.

The same problem can be seen here in your example when using FireFox 3: http://www.smartclient.com/index.jsp#_Data.Binding_Trees_Load.on.Demand

If you expand Charles > Ralph > Bhushan

Bhushan has a triangle indicating it can be expanded, a request is made to the server which returns with to expanded details. It would save the user a click if when Bhushan loaded it indicated it can’t be expanded.

Ignore that last question I deleted the isFolderProperty property by mistake.

I was just trying to enable reordering in a treegrid, using the same code above with either of these two attributes.

Firstly which one should I use?

canReorderFields:true, canReorderRecords: true

What should the server return when a move is successful?

How do I tell what the new order is server side?

FireBug Headers:

do	fetch
isFolder	false
isOpen	false
parentId	wxy
sectionId	wxy4
sectionName	WXY 4

No details are given about what position wxy4 should have in wxy. I move it from the 4th slot to the 2nd slot, but you can not tell this information from the server.

About the property to use for reordering nodes - check the docs.

Are you trying to establish a permanent stored order for these nodes? As in, there will be a DataSource field specifying the order, which you will be updating when the user drags?

The doc isn’t as helpful as for other components of treeGrids.

It suggests to me canReorderRecords is correct but I am unsure when you would use canReorderFields.

canReorderRecords - Indicates whether records can be reordered by dragging within this listGrid.

canReorderFields - Indicates whether fields in this listGrid can be reordered by dragging and dropping header fields.

The order of nodes will be saved in the database, the DS will have this additional field added. I just don’t know how to go about doing it.

TreeGrid extends ListGrid, and canReorderFields is an inherited method - it’s used as it is in ListGrid, to allow the user to drag columns around with the header button. This may not have occurred to you, as many applications of TreeGrid only require one column (that containing the tree itself).

If your DS will contain an additional field to stipulate child order, then unless I’m missing something it seems fairly obvious that’s how you communicate it to the server. Client-side, child sequence within a node will be determined by the child’s position within treeGrid.data.getChildren(node) - use that info to update your DS field.

But when I move a node up or down a server request is sent but no information about the new position of the node is sent.

Override http://www.smartclient.com/docs/6.5.1/a/b/c/go.html#method..TreeGrid.folderDrop. Make whatever changes you need to the underlying data (the “index” parameter looks interesting!) and then invoke “Super(‘folderDrop’, arguments)”.

The example it links to does not work:

http://www.smartclient.com/docs/6.5.1/a/system/reference/SmartClient_Explorer.html#treeDropEvents

I get “record is undefined” when I try and move a folder to another folder.

Hi Nick,

That example for folderDrop() shows how it can be used to recategorize records shown in a related list. That particular example is not trying to show how to reorder tree nodes, and it’s true there’s a crash if you try to reorder tree nodes, but that’s a flaw in the example (which we’ll correct) not the folderDrop API.

Unlike that example, you want to save the “index” parameter to the DataSource representing the tree.

Can you give a example of how the folder drop will use the index to construct the updateData so that it includes the position.

folderDrop : function (dragRecords, dropFolder, index) {
				treeTestDS.updateData(dragRecords, dropFolder);
				treeTestDS.fetchData();
		        say(index);
		    }

The treeGrid is able to submit the following to the server, however the get parameter name is useless _parent_isc_ResultTree_54 for being able to update the database with the change.

$42c	isc_ResultTree_54
_parent_isc_ResultTree_54	{sectionName:"Section: 9",sectionId:"id9",parentId:"root",isFolder:true,isOpen:true,orderby:"",children:[{sectionName:"Sub: 0 of Section: 9",sectionId:"sub0id9",parentId:"id9",isFolder:false,isOpen:false,orderby:""},{sectionName:"Sub: 1 of Section: 9",sectionId:"sub1id9",parentId:"id9",isFolder:false,isOpen:false,orderby:""},{sectionName:"Sub: 2 of Section: 9",sectionId:"sub2id9",parentId:"id9",isFolder:false,isOpen:false,orderby:""},{sectionName:"Sub: 3 of Section: 9",sectionId:"sub3id9",parentId:"id9",isFolder:false,isOpen:false,orderby:1},{sectionName:"Sub: 4 of Section: 9",sectionId:"sub4id9",parentId:"id9",isFolder:false,isOpen:false,orderby:""}]}
_selection_6	true
do	fetch
isFolder	false
isOpen	false
orderby	1
page	adminmenu
parentId	id9
sectionId	sub3id9
sectionName	Sub: 3 of Section: 9

Hi Nick,

Just a sanity check - did you know the SmartClient Reference is searchable? Because you’re passing parameters to methods that don’t match the documented method signature…

You need to add the index to each dragRecord and save them to the server via an updateData() call for each dragRecord.