[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Flex 4: Can't pre-select item in DataGrid (Array)

Posted on 2010-09-24
8
Medium Priority
?
1,153 Views
Last Modified: 2012-05-10
I'm polling a RemoteObject every 5 seconds using setInterval and the returned result (Array) is being fed into a DataGrid as the DataProvider. However everytime this happens the selected row deselects when the DataGrid is refreshed. So I want to re-select the item when the DataGrid has been updated.

So far I've tried capturing the selected row before the RemoteObject is called using:

    private function refreshDataGrid(e:ResultEvent):void
    {
        var selectedRow:Object = myDataGrid.selectedItem;
        myDataGrid.dataProvider = e.result as Array;
        myDataGrid.selectedItem = selectedRow;
    }

However this doesn't work. If I select the row and then do a "trace(myDataGrid.selectedItem)", the result in the Console is blank.

In another attempt I tried:

    private function refreshDataGrid(e:ResultEvent):void
    {
        var selectedItem:* = myDataGrid.selectedItem.itemId;
        myDataGrid.dataProvider = e.result as Array;
        myDataGrid.selectedItem.itemId = selectedItem;
    }

This doesn't work either.

Can anyone help me make this work? Any help would be greatly appreciated. Thanks in advance.
0
Comment
Question by:DReade83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 2000 total points
ID: 33753191
The problem is that you are using selected item ... even if the returned object has the same content ... it is not the same object (has a different object id).

What you need to do, is to save some criteria with which you can determin an equal object. Let's say the object has an id property. Then you need to save the id-value of the selected item. When getting the response you iterate over all returned objects and check their id attribute. If it matches the saved id, you set this as selected item.

If this doesn't work immediately, I would also suggest to set the item using "callLater" function because in some cases the grid needs to do some updating before you are able to set the selected item. this way you wait until Flex is finihsed updating everything and immediately after that the callLater function is executed ...
0
 

Author Comment

by:DReade83
ID: 33753264
I see what you mean. Is there no way to update only the data that's changed rather than re-create the DataProvider all over again when the result is returned from the RemoteObject? Effectively the objects would remain the same, just the properties of the objects would be changing.

The reason I want to do this is because when the DataGrid updates, there's a chance there will be a pause in-between the selection disappearing and reappearing as the DataGrid is re-populated. If the DataGrid were refreshing every 5 seconds it would become noticeable and possibly annoying from the end user's perspective.

Do you know if this is possible?

Failing that, are there any real-time solutions available for a Flex/PHP environment?
0
 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 2000 total points
ID: 33753880
Oh well ... of course ... this is a little more tricky though.

You would need to iterate over the old and the new list and to make lists of elements that were changed, added and deleted. After building these lists, you could remove the deleted and updated items and add the new and updated ones (If an updated Item was selected you would have to change the selection to the new object).

This approach is certainly the smother one, as the Table will not jump up and down while initializing.
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:DReade83
ID: 33753892
Are there no real-time Flex/PHP solutions available that would make this process easier to implement?
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33754001
Well this is exactly what Adobes ColdFusion stuff is for ... but that is really expensive.
0
 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 2000 total points
ID: 33754052
In the PHP world the only tool I have heard of is Zend:
http://www.flex888.com/832/zend-php-and-adobe-flex.html
http://devzone.zend.com/article/2019
Perhaps they offer components that also provide this type of functionality.
0
 

Accepted Solution

by:
DReade83 earned 0 total points
ID: 34172055
I've found a solution using for(), matching one of the items in an array to the ID I want to pre-select. See attached code.
for (var i:Number = 0; i < result.length; i++)
{
    if (dataGrid.dataProvider[i].ID == _id)
    {
        dataGrid.selectedIndex = i;
        break;
    }
}

Open in new window

0
 

Author Closing Comment

by:DReade83
ID: 34203489
Found a solution. See my post.
0

Featured Post

Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Ransomware, the malware that locks down its victim’s files until they pay up, has always been a frustrating issue to deal with. However, a recent mobile ransomware will make the issue a little more personal… by sharing the victim’s mobile browsing h…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question