Commit new value from itemEditor before itemEditEnd event - apache-flex

I have a DataGrid, with itemEditor as NumericStepper in a few columns. When a value in the DataGrid is edited, I would like to update several values displayed on the screen, and so want to call a updateValues() function.
First, I added this function to itemEditEnd event of the DataGrid, but the function is getting called before the new value is updated into the dataProvider and hence, the values I have in the function are the old values. Is there any other event that is fired after the values are updated into the dataProvider? or am I missing something?
Second, I tried putting this function in the change event of each itemEditor (duh!), but then again, the change event is fired, but the values in the dataProvider are the old ones.
Is there any way I can make the function updateValues() be called, every time a value is edited AND updated into the dataProvider, because there's where I am taking the values from?
Thanks a lot.

"In your event listener, you can examine the data entered into the item editor. If the data is incorrect, you can call the preventDefault() method to stop Flex from passing the new data back to the list-based control and from closing the editor." (source)
So yeah, it gets called before the dataprovider has the data.
Here's what you should read: Detecting Datagrid Edits. He talks about all the same stuff. Event priority is the ticket. Overly complicated is the Flex way. Cheers.

Related

Lightswitch HTML databinding to a details collection

I have a simple master/details relationship where one order can have multiple revenue allocations. The order has a collection that contains these.
I want to sum a property in my revenue allocation objects and ensure that it adds up to my order total. However, if I databind on the count property of the allocations collection this gets called when you first add an empty object and not when that object has been populated. So an empty allocation is added at the time the "Add allocation" screen is created and the databind function called. That of course means that when the save button on the "Add allocation" screen is clicked, the databind function isn't called again.
Anyone got any ideas? I basically want my databind function to be called when the save button is clicked in the "add screen" and not before.
This is the HTML client - NOT Silverlight
I'm pretty sure that the solution would be to use an OData query to get your aggregate data within the databinding function of the save button - or perhaps a separate button (e.g. "Tally Order Totals"). Exactly how you do that? A bit too hard for me to answer right now, but start with a new button TallyOrderTotals and a new data field for your total. Edit the post_render event for TallyOrderTotals and lookup the allocations in the javascript in which you data bind the value of the new data field.
Somewhere you will need a piece of code that looks something like this:
myapp.activeDataWorkSpace.<datasource>.RevenueAllocations
.filter("OrderID eq " + msls._toODataString(<orderID>, ":String"))
.execute()
.then(function (result) {
// assign the result somewhere
}
I'm not saying that's something you can cut-and-paste - but definitely look at the msls.js documentation and see what you can do with querying your data inside the event context.
One quick point however - if you only need to calculate that total as a verification step, consider doing it in the SaveExecuting() event on the server side. This will allow you to throw an exception back up the tree to your HTML page which the msls.js script should render on the client side.
Hope that helps. :)

flex how to refresh already created view

How can I refresh view after a certain event?
I have a view which contains multiple groups. I want to show or hide some groups.
onCreationComplete() or initialize() method works only at the beginning of the view creation.
Try invalidateDisplayList() on the view
Let me know if that doesn't do the trick and we'll try some other tricks.
I personally don't like the answer that says to call invalidateDisplayList (sorry no offense Nate nothing personal). I feel it's too vague and doesn't explain what this does under the hood and furthermore you shouldn't have to call it directly in cases such as the one explained in the OPs question. You can simply create booleans that are bindable for each of the groups you'd like to show/hide then in the event handler set those booleans to the appropriate value and if they are bound to the visible and include in layout properties of the containers those containers will internally call invalidateDisplayList after calling set visible and consequently commitProperties.
This is basically what happens under the hood as I understand it: The way this works is values aren't committed or used to update the display until the next frame this way it doesn't get bogged down doing unnecessary layout calculations. So you update the bindable property which fires an event which triggers a notification in the listener (in this case a function that sets the property on your control), that in turn passes along the value to the control which sets an internal flag to update the property and calls invalidateProperties. When it hits the next frame redraw it sees that the properties flag is dirty (true) and then calls commitProperties, this computes/sets the appropriate values (possibly also invalidating then "fixing" the size using invalidateSize() and measure()) and calls invalidateDisplayList, then during the same frame it sees that the display list flag is dirty so it calls updateDisplayList, here it uses the values of the properties to draw appropriately.
You should also be able to achieve this using states, which add or remove children from the display list based on an array of "actions" for each state.

How to Auto Refresh <mx:List

I want to use event timer every 3 seconds to refresh List. I have created event timer but don't know about function to refresh List.
has anyone ever did this?
I'll appreciate your help, thanks
You should bind the List to a datasource (arrayCollection). Whenever the arrayCollection being updated, it will refresh the list automatically, example
<mx:List dataProvider="{myAC}"/>
where myAC is arrayCollection that can be changed to another arrayCollection.
Code samples, check on this line ( "section Binding to arrays" )
Take note that it's better to bind instead of doing something like
list.datasource = anotherArrayCollection;

stack overflow on XMLListCollection collectionEvent

I'm working on a Flex 3 project, and I'm using a pair of XMLListCollection(s) to manage a combobox and a data grid.
The combobox piece is working perfectly. The XMLListCollection for this is static. The user picks an item, and, on "change", it fires off an addItem() to the second collection. The second collection's datagrid then displays the updated list, and all is well.
The datagrid, however, is editable. A further complication is that I have another event handler bound to the second XMLLIstCollection's "change" event, and in that handler, I do make additional changes to the second list. This essentially causes an infinite loop (a stack overflow :D ), of the second lists "change" handler.
I'm not really sure how to handle this. Searching has brought up an idea or two regarding AutoUpdate functionality, but I wasn't able to get much out of them. In particular, the behavior persists, executing the 'updates' as soon as I re-enable, so I imagine I may be doing it wrong. I want the update to run, in general, just not DURING that code block.
Thanks for your help!
Trying to bind the behaviour to a custom event rather than the CHANGE event.
I.e. do what you are doing now, but dispatch and handle a custom event to do the work.
Have you considered using callLater?
Does direct manipulation of XMLListCollection's source XMLList have the same results?
Have you considered something like:
private function changeHandler( event:Event ):void
{
event.target.removeEventListener( event.type, changeHandler );
// your code here.
event.target.addEventListener( event.type, changeHandler );
}

How to determine last deselected item in a TileList?

My TileList has allowMultipleSelection on. I am using itemClick to call a function. I can use listEvent.currentTarget.selectedItem to determine what object was just clicked on if I am selecting, but when I ctrl + click to deselect an item, it automatically selects something else in the TileList, thus changing the selectedItem. It seems like ctrl + clicking to deselect changes the target before the itemClick function is run. Is there a way to figure out what was just deselected?
I can use selectedItems to get the same end functionality I need. However, I am concerned about performance when the selectedItems collection gets really long. We are using blazeds to send the data back and forth and it would be much faster if we sent the one item that was added/removed then the whole thing each time.
I'm a bit surprised that you seem to be saying that "itemClick" isn't being dispatched in each case. I wonder if you should try listening to the "change" event instead?
What about adding a property called "previouslySelectedItems" and doing a comparison between that and "selectedItems" to figure out what changed? After the comparison is done, set previouslySelectedItems = selectedItems.

Resources