Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Self-Referential Field in Component XML

    SmartClient Version: v10.1p_2016-12-11/Enterprise Deployment (built 2016-12-11)
    Chrome Version 64.0.3282.167


    I have a component xml for a ListGrid of objects that can be (but aren't always) hierarchical. I defined a field similar to what is shown in the API docs for foreignKey, but I set it to nillable since it can be null:

    Code:
    <DataSource ID="myDS" allowAdvancedCriteria="true">
        <fields>
            <field name="objectKey" title="Key" hidden="true" type="integer" primaryKey="true" required="true"/>
    
            <field name="name" title="Name (Full)" hidden="false" type="text" canEdit="true"/>
    
            <field name="parentKey" title="Parent" hidden="false" type="integer" nillable="true" editorType="SelectItem" canEdit="true"cellAlign="center" foreignKey="objectKey"/>
        </fields>
    
    //OperationBindings here
    
    </DataSource>
    "objectKey" is defined as a primary key in my database and is set from a sequence in said database.

    "name" is just a String name given to each object.

    "parentKey" can be a null value if the object has no parent object, but I'd like to display a SelectItem on the grid record containing other objects from the same table/datasource that can be set as a parent object.

    When the screen loads I can view all the defined records, and I have no issue creating or updating records while leaving parentKey empty. However, if I double click on the field for parentKey I get an empty SelectItem instead of a list of defined objects from the same table/datasource. I've tried adding displayField and valueField attributes to parentKey, setting them to name and objectKey respectively, but there's no change.

    What I'd like is this: If I have a ListGrid with 2 records already defined:
    objectKey name parentKey
    1 'Object A' null/empty
    2 'Object B' null/empty





    I'd like to be able to add a third object, with objectKey=3 and name='Object C' and have the SelectItem in the parentKey column display 'Object A' and 'Object B' as possible options, 2 to the parentKey attribute of 'Object C' if I select 'Object B' as its parent:
    objectKey name parentKey
    1 'Object A' null/empty
    2 'Object B' null/empty
    3 'Object C' 2

    Is what I'm trying to accomplish possible? If so, how can I achieve this?

    Thanks in advance for any help.


    #2
    With those settings, the SelectItem will consider "myDS" as an implicit "optionDataSource" and send a request for all records, which will then be displayed using the specified displayField or a heuristically guessed displayField (which would be your "name" field in this case). The on-by-default "fetchMissingValues" behavior will also ask the same DataSource for displayField values for the current chosen related record.

    This all seems to be what you want, so if you're getting a blank, your server simply seems to be responding incorrectly to the requests from the SelectItem.

    But you've given no information as to what requests are sent or what the responses are, or even what kind of DataSource this in, so we can't help further, yet.

    Comment


      #3
      Hi Pro-crastinator,

      please note that your foreignKey definition should most likely be foreignKey="myDS.objectKey".

      Best regards
      Blama

      Comment

      Working...
      X