TreeGrid and loadDataOnDemand

I have a TreeGrid that I want to load the children on demand for.

I do not have control over the xml that is returned from the server, as I am trying to utilize this client code with an existing backend.

My response has something like <data children=“Y”>…</data> which the server is indicating to a client that there are children, so you can make a subsequent call to retrieve them.

However, in testing this with SmartClient, it seems like just having the attribute “children” (whether set to N or Y) is causing the TreeGrid to not make another fetch when the node is expanded. I find this behavior to be odd.

Am I missing something? ( I can post some sample code if necessary ).

My first guess at a work around would be to modify the transformResponse to remove the children attribute, but I’m not sure offhand how to remove properties from the DSResponse.data.

Thanks for any help or clarification.

Put loadDataOnDemand:true, in your tree grid definition.
You need to have following fieldefinitions in data source if you want children type tree:
{childrenProperty:true, name:“data”},
{name : “Id”, primaryKey:“true”, rootValue:“1”},//Unique Id identifies each element

{name : “parentIdField”, foreignKey:“parentId” },//Parent Id represents relation of parent & child.

for example
<data>
<name>A</name>
<Id>1</Id>
<parentId>0</parentId>
</data>
Children:
<data>
<name>B</name>
<Id>2</Id>
<parentId>1</parentId><!-- It tells that this is a children of A–>
</data>

It is always good to have id & parentId … in your data

mention following property in tree grid definition to tell weather it has children or not …
dataProperties: { isFolderProperty : “your property name” },

-Sravan

gurugubelli:

Thanks for the quick response!

I’m not sure I have explained my problem very well.

Let me post the code I wrote to test this issue:

isc.DataSource.create({
  ID:"testDS",
  dataForamt: "xml",
  dataURL: "incoming.php",
  contentType: "text/xml",
  dataProtocol: "postMessage",
  httpMethod: "POST",
  operationBindings: [
    {operationType:"fetch", dataProtocol:"postMessage"},
    {operationType:"add", dataProtocol:"postMessage"},
    {operationType:"remove", dataProtocol:"postMessage"},
    {operationType:"update", dataProtocol:"postMessage"}
  ],
  recordXPath:"//data",
  fields:[
    {name:"id", title:"ID"}
  ]
});

isc.TreeGrid.create({
    ID:"myTree",
    dataSource:"testDS",
    showHeader:false,
    leaveScrollbarGap:false,
    canAcceptDroppedRecords:true,
    canReparentNodes:false,
    selectionType:"single",
    modelType: "children",
    idField: "id",
    loadDataOnDemand: true,
    autoFetchData: true,
    fields: [
      {name: "id"}
    ]
});

*note: I’ve tried both 6.5 and 7.0RC

incoming.php is simply as follows:

<?php
$out = <<<OUT
<response>
<data children="Y">
<id>12345678</id>
</data>
</response>
OUT;
print $out;
?>

This will perform a fetch and displays a closed folder. When I expand the folder, a child displays with no data, and no fetch is performed.

However, if i change the php to reply with <data> and no attribute of children=“Y” then it works as expected. This is to say, a closed folder is displayed, when I expand the folder it performs a fetch to the server.

And again, unfortunately I cannot change the response (this is just a test program) from my server, and would have to figure out a solution on the client side.

Hi kbessinger,

By default the Tree will assume that “children” contains actual children, not just a flag indicating whether a node has children. You can change the property name used by creating a DataSourceField marked childrenProperty:“true” (see DataSourceField.childrenProperty. For example, just add:

    {name:"unused", childrenProperty:true}

You may want to override Tree.isFolder (via TreeGrid.dataProperties) or set Tree.isFolderProperty to enable correct detection of whether something is a folder according to the format you are using. But we’d need to see more about the protocol (eg how children are intended to be fetched, and what that response looks like) to really comment.