itemIndex property

num get itemIndex

Gets the index of this Panel's data if it was created to represent an item in its containing Panel's Panel#itemArray. The default value is NaN.

This is only set internally by code such as #rebuildItemElements or Model#insertArrayItem when building or shifting Panel representing items in the Panel whose Panel#itemArray was set or bound to an Array of value.

This property can be used in data bindings within the item template to produce values that depend on its position in the item Array. For example:

 $(go.Panel, // the item Panel
   . . .,
   new go.Binding("itemArray", "someProperty"),
   {
     itemTemplate:
       $(go.Panel,
         // set Panel.background to a color based on the Panel.itemIndex
         new go.Binding("background", "itemIndex",
                        // using this conversion function
                        i => return (i%2 === 0) ? "lightgreen" : "lightyellow")
                  // bound to this Panel itself, not to the Panel.data item
                  .ofObject(),
         $(go.TextBlock,  // a trivial item template, just showing some text
           new go.Binding("text"))  // sets TextBlock.text = data.text
       )
   }
 )

The main element of a Spot or Auto or Link Panel, or the first TableRow or TableColumn element of a Table Panel whose #isPanelMain property is true, will not have this property set to a number, because it will not have been created by #rebuildItemElements.

Implementation

_i2.num get itemIndex => _i4.getProperty(
      this,
      'itemIndex',
    );
set itemIndex (num value)

Implementation

set itemIndex(_i2.num value) {
  _i4.setProperty(
    this,
    'itemIndex',
    value,
  );
}