On Tue, Apr 26, 2011 at 11:09, slah <[email protected]> wrote:

> for each row of a table, I'm maintaining an object (marker for a map).
> Initially I loop through table rows and create my array of markers from 0
> to
> rowcount-1.
>
>            var infowindow = null;
>
>            var tm = this._bottomTable.getTableModel();
>
>            for (var i = 0; i < tm.getRowCount(); i++) {
>
>                var contentString = "some html info";
>
>                                                             );
>                var point = new
> google.maps.LatLng(tm.getRowDataAsMap(i).LAT,
> tm.getRowDataAsMap(i).LON);
>
>                var marker =  new google.maps.Marker({
>                                position: point,
>                                map: _map_wf,
>                                title : tm.getRowDataAsMap(i).LVEH,
>                                html : contentString,
>                                animation : null });
>
>                google.maps.event.addListener(marker, 'click', function() {
>                                infowindow.setContent(this.html);
>                                infowindow.open(_map_wf,this);
>                        });
>
>                this._current_pos_markers.push(marker);
>            }
>
>         this._bottomTable.resetSelection();
>
>        },
>
>
> Then each time the user clicked on a row, I just display the object
> corresponding to the clicked row (same index).
>
> the problem is when the user sorts the table, the index of the selected row
> no more corresponds to the index of the array I'm maintaining and so I
> display a wrong object.
>
>
>     var that = this;
>
>      table.getSelectionModel().addListener("changeSelection", function()
>      {
>        table.getSelectionModel().iterateSelection(function(index)
>        {
>         // Pb here when sorted:  index in markers array do not correspond
> to
> the selected index
>         var marker = that._current_pos_markers[index];
>
>         var point = marker.getPosition();
>         var markerBounds = new google.maps.LatLngBounds();
>         markerBounds.extend(point);
>         _map_wf.fitBounds(markerBounds);
>         _map_wf.setCenter(point);
>        }
>
>      })
>      }
>
>
> I wonder if somebody here knows an efficient way to handle such situation,
> like attaching each object to the corresponding row or is there another
> hidden index that stay the same even if the table is sorted. I'm running
> out
> of ideas :)
>

 You can store your additional data directly in the row data array, instead
of in a separate array. You are already using map data, so you can store
additional data in that map.

           var infowindow = null;

           var tm = this._bottomTable.getTableModel();

           for (var i = 0; i < tm.getRowCount(); i++) {

               var contentString = "some html info";

                                                            );
               // Get the map for this row
               var rowData = tm.getRowDataAsMap(i);

               var point = new google.maps.LatLng(rowData.LAT, rowData.LON);

               var marker =  new google.maps.Marker({
                               position: point,
                               map: _map_wf,
                               title : tm.getRowDataAsMap(i).LVEH,
                               html : contentString,
                               animation : null });

               google.maps.event.addListener(marker, 'click', function() {
                               infowindow.setContent(this.html);
                               infowindow.open(_map_wf,this);
                       });

               // Save the marker in the map
               rowData.marker = marker;
           }

        this._bottomTable.resetSelection();

When you set your data initially, you should set the second parameter to
setDataAsMapArray() to true, to tell it to remember your map additional
data.

Derrell
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to