PDA

View Full Version : Help needed on DataView with mouseenter



AndyPC
1 Apr 2011, 2:53 AM
Hi. I have a Dataview with it's source data attached as "data: [an array variable]". It display's perfectly, but now I have to make a map snap to an items position. I have the mouseenter mechanism working, but have two problems.

1 - The Index passed in the event is always -1
No matter what I try, the event variable that is supposed to have the selected items index, always contains -1

2 - Access to the underlying 'data' in the DataView to get the XY coords
Even if I could get the index, I have no idea how to get to the variables in the original Array/Object to retrieve the items XY coordinates

Screamy
1 Apr 2011, 5:47 AM
Did you configure the 'mouseenter' event handler in-line, something like?



var dv = new Ext.DataView({
emptyText: 'No data',
itemSelector:'div.someElement',
listeners: {
mouseenter: function(dataview, index, node, eventObject) {
// do something ehre.
}
},
multiSelect: true,
store: someStore,
tpl: someTpl
})

AndyPC
1 Apr 2011, 5:59 AM
Basically, the datasource was an Array attached to 'data' in config, with no 'store' defined. Finally figured that a store is essential in looking up the source data, so used some info from here (http://miamicoder.com/2009/ext-js-tips-binding-an-array-of-objects-to-a-gridpanel/) to build an ArrayStore from my array.

My source data varied in field definitions but fortunately the data object had an array describing the fields, so I looped through these constructing an array of Record Field definitions to apply to the array store, then I looped through the results in the data object and added them to a simple array, as well as adding extra properties to each array object. Finally bound those 2 up in an ArrayStore, and attached it to my DataView.

Just a note to anyone else having problems with stores - use JSLint (website (http://www.jslint.com/)) to check your code syntax ("Clear all options" for basic checking). My biggest breakthrough was finding a syntax error that was stopping it all from ever working.

Thanks all who looked and thought about it!