first value should be selected when loading the data in ComboBox - apache-flex

I had a comboBox and loading the datadynamically from the server. i need to display the first value in comboBox as a selected value and based on the value data should be populated on the grid. Please send me a sample example on the same if nay one knows.
thanks,
Ravi

You can select the first value by setting: selectedIndex=0 or set the selectedItemproperty.
But you should make sure that there is an item which you can select. This could be for example done in the setter of the dataProvider.

Another way to make sure that you have data is add a ChangeWatcher to the dataProvider, so that you will be notified when new data is bound. Then you can simply traverse the data and select whichever one you want, in your case selectedIndex=0;

Related

In App Maker, can you fake valueIsRecord with a dropdown field?

In App Maker, what is the simplest way to achieve the same result with a dropdown box that you can with a suggest box, which can return the whole record when you make a selection giving you the ability to assign associated record values to other fields on the page?
Consider a data model with three fields, (Code, Description, and Severity). Add a dropdown box to select the Code. Have the selection, (probably using onValueChange or onValueEdit), write the selected Code's Description to a label field beside the dropdown box. The Code's Severity will also be used to affect the style in some way like background color or something, but for this answer, merely assigning the value to a scripting variable will be good enough. It's the record value access and assignment mechanism I am after.
Clarification: This data model will not be the page's datasource. It is a secondary reference table used for assigning a code to a ticket. You can also assume that a record value will be written to a field in the page's datasource as well.
I would appreciate the simplest low code solution as we will have non-programmers attempting this. Thanks.
As long as you leave your value binding on the dropdown blank the following should work:
Set the options binding to:
#datasources.YourDatasource.items
You may want to consider changing the 'Names' binding to be the projection of a particular field in this datasource otherwise the values showing in your dropdown will only be the 'keys' from this datasource.
Then in your onValueEdit event you will gain access to individual fields like this:
var item = widget.datasource.item;
item.YourFieldToEdit1 = newValue.YourOtherDatasourceField1;
item.YourFieldToEdit2 = newValue.YourOtherDatasourceField2;
That would probably be the simplest way.

Keep selection when refreshing datagrid in ActionScript

I'm working on my first ever AIR application with flashbuilder - just so you know.
I've bound a mx:DataGrid component to a DataProvider which is a mx:HTTPService fetching an xml file with items. To keep the data up to data I'm polling the webservice on a given interval.
My problem is that I loose the currently selected item in my DataGrid when the data is updated. I've tried to save the DataGrid.selectedIndex and set when the data is updated, but I'm not sure when to do it?! The closest I've come is to restore the index when the updateComplete event of DataGrid is fired. This works, but the selection first fades away and then fades in - not updated soon enough.
So what is the best way to keep the selection? (only one selected item at a time)
And as a side question: is there a convenient way to only update the data when it has actually changed?
Thankful for any suggestions!
I'll start from the bottom, the only way to only update the data when it has changed is to pass a check on the data on the server side to see if data has changed and make that a call before the actual update. So in short, you make two calls, one to see if the data has changed, which is a server side query, and the next only if that returns true, which updates the data.
Alternatively, you can also get the update, and compare it to your current data, and only update the UI if that data is different, but I have a feeling you mean the former answer of only doing the update CALL at all, if the data has changed.
As for the other solution, after you've saved the selectedIndex, do this inside your updateComplete:
private function yourDataGridUpdateComplete(event:FlexEvent):void{
yourDataGrid.selectedIndex = yourIndex;
yourDataGrid.validateNow();
yourDataGrid.scrollToIndex(yourIndex);
}
The DG uses the UUID of the data items to determine whether the item should be still selected after a refresh. If the data items don't implement IUID they basically get random values created each time they are added to the DG.
If your data items implement the IUID and you use a consistent value (DB sequence number for example) the DG will "know" that after a refresh, the data item is the same one as before.

Datagrid, getting and setting individual cell values

I have Flex 4 DataGrid, what I would like to do is when an cell has been edited,
I would then like to walk through the values of that column and preform math on the values, eg I want to total up certain values.
1) How do I reference individual values of a specific column so that I may set them.
2) How do I then set those values or should I create a new column array and pop it in place of that column.
Please and thank you in Advance.
Craig
var data_field:String = dgViewPreview.columns[6].dataField; //for 6th column
ListCollectionView(dataGrid.dataProvider).getItemAt(requiredRow)[data_field] = newValue;
Thanks to Armagosh for the idea.
You can also listen to CollectionChangeEvent of your dataProvider, check its type, and if this is a PropertyChangeEvent that triggered it - check the name of the property that was changed, and depending on the property perform the calculations. This will work if you change the value not only from dataGrid. And, you would want the calculated values to be marked [Bindable] to have the changes reflected in the UI.
A way to do it in Flex 3 would be to add an event listener on the grid for the ItemEditEnd event. In the handler of that event, you would iterate over your the dataprovider and perform and calculations and updates needed.
When you update the items in your dataprovider, the updated values will be reflected in your grid.
I imagine you would do something similar in Flex 4.
--ron

Flex dataGrid how to color empty rows?

My problem is that empty rows (if there are more rows that dataSource items then there are empty rows) look identical to rows binded to dataSource items which are empty (see the difference?).
The only way to know the difference is to hover over them with the mouse, and if they are empty there's no color change, otherwise there's the blue background of the selection..
I want to change the color or in some way hide empty rows, those that are not bound to a dataSource item.
How can I accomplish this?
You can format your DataGrid using ItemRenderer.
The itemRenderer is a display object that get the data from the data provider and display it in the grid.
Writing your own logic can help your specific data display in general. in this case, check for data on the ItemRenderer object creationComplete. it the data is null or empty - display a sign (or whatever).
See this link as reference:
http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/
Enjoy!
I'm not sure if this is exactly what you are looking for but I cut off my rows at the end of my dataprovider like this:
myGrid.rowCount = myDP.length();
This can of course be modified with some simple logic to have min, max, or if it's a data entry type of grid length()+1.

Get Changed Rows of GridView ASP.Net

How Can I find all the rows that has been changed in gridview. I can not use Ajax in any form
First get the contents of your grid before it was changed (such as caching the results of the original gridview datasource binding). Then go through the dataset/datatable/however you want to store it, and compare the contents with the current rows of the gridview.
There's no real efficient way to do this, no method like GridView.GetAllChangedRows(). So, what you might do instead is keep a behind the scenes List that you add to each time a row is modified (use the RowUpdated method), then clear this list when needed.
It depends upon how many columns you want to edit in a row.
If you have only one editable column in a row then you can associate a javascript method with that control which you want to modify and in that method you can get a rowid which you can save in another hidden field and in server side you can get all rows whose ids are stored in hidden field.
If you have whole row editable in that case the best approach I think you should save the original data source somewhere and also set a javascript method with rowclick event to get rowid which user selects. Then when user clicks on submit button get all rows whose row ids are stored in hidden field then compare those with same rowid in datasource. This is the best approach from my point of you.
Let me give you an example, suppose there are 1000 rows in a grid and user clicks on only 180 rows. In that case we will compare only 180 rows and wont compare rest of the rows.
Please let me know if somebody has better idea then this.

Resources