pickTree, displayField, valueField

I’m trying to extend Office Supply Catalog demo to:

  1. Add a description field to the category items;
  2. Display the description value instead of the categoryName in the PickTreeField in the edit form.

This is the modification in the supplyCategory data source:
…
<field name=“description” title=“Description” type=“text” length=“128”
required=“true” />
…

This is the modified pickTree definition:

    {name:"category", editorType:"pickTree", dataSource:"supplyCategory",
     emptyMenuMessage:"No Sub Categories", canSelectParentItems:true,
     displayField:"description",
     valueField:"categoryName"},

I expected to see description field values in the labels of the pick tree but categoryName is shown.

I tried to override getDisplayFieldName() and getValueFieldName() and it doesn’t work either.

Hi catalinmerfu,

It’s not clear why it’s not working for you, but you can see that exact use case in this example, working properly.

Check whether your DataSource changes are actually making it into the page output - XML DataSources loaded by an <isc:loadDS> tag appear in JavaScript form if you View Source on the page.

On second thought, that example is working for a different reason - the displayField setting is not what causes the “Name” field to be chosen.

You can set DataSource.titleField to the name of the field you want to use as the node title.

Thanks,

I commented out the Trees/Editing example

isc.SearchForm.create({
    top: 270,
    width: 200,
    height: 30,
    fields:[
        {editorType: "pickTree", showTitle: false, canSelectParentItems: true,
         dataSource: "employees", 
//            displayField: "Name", valueField: "EmployeeId",
         change: "employeeGrid.fetchData({ReportsTo: value})"}
    ]
});

and data labels in the tree are the same. It seems the PickTree control is doing some reflection and is picking up the display field based on the “Name” field name and the value field based on the primary key attribute.

Setting the titleField on the DataSource works. But now it wouldn’t be possible to add another column to the DataSource and use the same DataSource with 2 pick trees, each getting the display label from a different column.

If instances in the Employee category would participate in 2 hierachies, for example there would be a second foreign key

        <field name="isMentoredBy" title="Mentor"
          type="integer"  required="true"
          foreignKey="employees.EmployeeId"  rootValue="1"/>

there doesn’t seem to be a way to specify which hierachy I want to display in the tree. There should be an attribute for configuring the foreign key that determines the hierarchy:

...
        {editorType: "pickTree", showTitle: false, canSelectParentItems: true,
         dataSource: "employees",
         foreignKey: "isMentoredBy",
         displayField: "Name", valueField: "EmployeeId",
         change: "employeeGrid.fetchData({ReportsTo: value})"}
    ]
});
...

Hi
Yes it looks like there’s a bug in 6.0 with displayField on pickTreeItems.
Our engineers will be fixing this for our next release.
In the meantime, a workaround you can use is:

For example in the Trees/Editing demo you could show the “Job” field rather than the “Name” field as follows

 {editorType: "pickTree", showTitle: false, canSelectParentItems: true,
    dataSource: "employees", 
    buttonProperties:{
        menu:{
            fields:[{name:"Job", width:"*"}, "subMenu"],
            getSubmenu:function () {
                var submenu = this.Super("getSubmenu", arguments);
                if (submenu) submenu.setFields(this.fields.duplicate());
                return submenu;
            }
        }
    },
    change: "employeeGrid.fetchData({ReportsTo: value})"}