Forum Discussion

Hannah15's avatar
Hannah15
Channel Surfer
12 months ago
Solved

How can we set custom fields in the MarkupGrid XML component?

The MarkupGrid node has a field called 'itemComponentName'. This should be set to the name of a custom XML component. It is used to display each item in the grid

For this XML Component, there are a few fields mentioned in the documentation. If we set fields of the same name, their values are populated by the content given to the MarkupGrid Node. 
But how do we set custom fields of the XML Component?

This is all the SceneGraph documentation has to say on the matter:
"If the XML component contains interface fields that match the names shown in the table below, those fields will be updated by the MarkupGrid node."
ref: https://developer.roku.com/docs/references/scenegraph/list-and-grid-nodes/markupgrid.md#markupgrid-xml-component 

For example purposes, we'll call the MarkupGrid node 'grid1' and the xml component 'itemTemplate'.

<MarkupGrid 
    id = "grid1" 
    itemComponentName = "itemTemplate"
/>


Since the XML component is not directly included as a node in the xml file, we cannot access it like we usually do i.e.,
m.itemTemplate = m.top.findNode("itemTemplate")

Sow how can we set values for custom fields of the itemTemplate node?

A current use case I need this for is to pass the index of the focused item to the XML component from the MarkupGrid. And there is no default field for this according to documentation.

  • You can't set fields yourself on your item components. If there is extra data you need to give them you would usually add this to the content nodes that your items will receive from the Grid.  

4 Replies

  • You can't set fields yourself on your item components. If there is extra data you need to give them you would usually add this to the content nodes that your items will receive from the Grid.  

    • Hannah15's avatar
      Hannah15
      Channel Surfer

      Oh interesting.
      So if we added them to the content node using a key 'val23', and then created a field on the item component with the same id as the key, the content node should set the field?

      • Chris-DP's avatar
        Chris-DP
        Binge Watcher

        No but your comment can read the new field off the content node. 

        Value = m.top.itemContent.val23