A5.ListBoxgetIndex Method
Syntax
A5.ListBox.getIndex(value)
A5.ListBox.getIndex(index)
A5.ListBox.getIndex(customMatch)
Arguments
- valuestring
The value of the row.
- indexnumber
The render index of the row.
- customMatchobject
Custom matching of rows. This is useful if the row might not be rendered because of filtering or sorting.
- typestring
The type of match to perform. Values can be "index", "match", "match-first", "match-last" or "match-all".
- indexnumber
If the "type" is "index" then this is used to select an item by the index in the data or the list before sorting and filtering.
- matchfunction(data,index)object
The function to use to match rows in the list, or an object with matching values.
- dataobject
The data of the row.
- indexnumber
The index in the list data of the row.
- indexarray
The found index(es). This will be an array of one or more objects.
Description
Get the indexes of row(s) in the list.
Discussion
The get index method will return an array of objects for each match that is found. Each object will have a property of "renderIndex" and "index". The "renderIndex" is the index of the item given current list filtering and sorting. A value of -1 is returned if the item is not rendered in the list. The "index" if the index in the data for the list before filtering and sorting. A value of -1 is returned if the item is not in the list data.
When an object is passed in, a custom match is done. This can either be to match a given index, or to match rows with a function or object. The types of "match" and "match-first" will return the indexes of the first match found. The "match-last" type will return the indexes of the last match found. The "match-all" type will return as many matching indexes as are found in the list.
Matching can be do with either a function or object. When using a function then the function will be called with the data and index for each row. If true is returned then the "index" and "renderIndex" for the row will be returned. When using an object, one or more columns of data in each row can be match by the corresponding column value from the passed in object.
Example
// To get a pointer to the A5.ListBox class see {dialog.object}.getControl // assume lObj is a pointer to an instance of the A5.ListBox class var indx = lObj.getIndex('ALFKI'); // get the index for the row with a value of "ALFKI" indx = lObj.getIndex(2); // get the index for the 3rd row currently rendered in the list indx = lObj.getIndex({type: 'index', index: 2}); // get the index for the 3rd row in the list list data - depending on sorting and ordering, this may be different from the result of the previous getIndex lObj.currentState = 'MA'; indx = lObj.getIndex({ type: 'match-all', match: function(data,index){ if(data.ContactName == 'Fred' && data.State == this.currentState && index < 100) return true; return false; } }); // get all of the indexes that have a "ContactName" of "Fred", a "State" of the stored "currentState" value, and an index less then 100
See Also