Flex 4 How do I access a specific cell by index? - apache-flex

I would like to edit a cell by the row and column indexes so essentially do the following:
advDataGrid[2][3] = "Dogs"
so that I am setting the data grid row 2 and column 3 to Dogs. I cannot for the life of me figure out how to do this!
Side note: I need this because I am trying to allow the user to copy a section of an excel file to a section of an AdvancedDataGrid like Google Docs does. I am using this idea to do it: http://mannu.livejournal.com/348299.html
Thanks! Any help will be greatly appreciated!

In general you want to operate on the dataProvider rather than the presentation (AdvancedDataGrid). So in your case, I would get the item associated with the specified row from your dataProvider and modify whichever element is specified to "Dogs". So something like this: adg.dataProvider[row].someColumnData = "Dogs"
EDIT: "someColumnData" refers to whatever property you have set for the column to display. So when you defined your AdvancedDataGrid's columns, you set the 4th column to use the "someColumnData" property of the items in your dataProvider, and you want to change the value in the 4th column, then you'd set it as described above. Hope that clarifies things.

Flex components are data driven, so you should modify the data provider of the grid.

What if you want to edit specific individual cells, eg I want to to keep running totals of some cells in other cells, IE: as a user edits I update whole columns.
Surely their must be a way to walk the array and get Column4.row6 = something.

Related

How to make a row in a grid not appear if it's value is 0?

I only have two fields in my grid. Just need the entire row to not appear, if the value in one of the fields is 0.
There are multiple solutions for your need, but this one is working for me in a similar setup.
Following code is in the PostBuild event of the component:
Local Rowset &rs;
&rs = GetLevel0()(1).GetRowset(Scroll.MainRecordOfTheGrid);
&rs.Flush();
&rs.Select(Record.MainRecordOfTheGrid, "WHERE FieldA<>0 and FieldB<>0");

How to line up data in a UITableView cell?

I have this UITableView (http://imgur.com/3YQzm) that I want to list 3 textfields on each row. The info is stored on a SQLite d/b. The first row I need for titles.
How can I list the info in each row so it looks "nice" (i.e. lined up in columns)? Do I need a custom cell for this?
As far I know, you have to put the labels in the specific locations, so you have to define the coordenates for a nice look. I don't know if you are using a xib file for the cell, but, for this case, is better to use it. In the xib will be easy to set the correct location for your labels.

AdvancedDataGrid (grouping) quick jump to row

I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun

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.

"freeze" one column in flex datagrid

I'm using a datagrid to display a column of date ranges and several columns of data. I'd like to make the first column (the date ranges) fixed; i.e. that column stays in place when the user scrolls the other columns. That way, the dates column will always be visible as the user scrolls through many data columns. I don't see a datagrid property for this; anyone have a solution? TIA
lockedColumnCount (and lockedRowCount) is more than likely what you are looking for.
http://livedocs.adobe.com/flex/3/langref/index.html
The reason you probably didn't see it is because it is part of the DataGridBase and not part of the DataGrid class itself.
use locked column count property
lockedColumnCount=”1″ height=”96″ horizontalScrollPolicy=”on”
verticalScrollPolicy=”on” width=”397″>

Resources