Flex Datagrid insert row below current row - apache-flex

my application needs to allow users to insert rows below the current datagrid row. My solution is to to add a row to the dataproviders collection. This works, but the row does not appear beneath the current row the user clicked on.
The Datagrid has a default sort order (date ASC), which re-orders the data...so this seems to affect the position of the row in the grid.
Any ideas how to fix this?

Two possible answers:
1. define your own sort function that sorts according to item order in dataprovider (i.e. it does nothing), and assign it to the sortFunction property
2. simply comment out the sorting of the data inside the component.

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");

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.

How to get proper row index values of grid view after sorting

I have an asp.net application in which I am using a grid view. Paging and sorting are applied to the grid view. One action what I am doing is on click of any grid view row, am getting the column values of the selected row and redirecting to the other page.
The problem is after the grid view is sorted, if I click on any of the row in ayy page (paging index), am getting only first page values even though the visible row is different.
I am getting the row values in gridview_rowcreated() method and putting in some variable. In sorting scenario, before sorting is done, the gridview_rowcreated() method is called but not after the sorting is done.
In case you still need an answer to this...
You should be using the gridview's SelectedIndexChanging event with something like the following:
gridView.Rows.Item(intNewIndex).Cells(# of column, zero-based).Text
This will give each cell's current value, you'll just have to loop through each cell and assign each cell's value to desired variable(s).
Hope this helps!!!

How to disable selected columns in a datagrid in flex for selected rows?

Is there any way to disable a few columns for a particular row in flex datagrid?
I have a datagrid with about 10 or more columns, say for example a few column names are: Item Id, Item Name, Item Status and VerifiedState. Initially I want the column Verified State to be disabled.
Now When the value of the column, Item Status is Review Passed for a particular row, I want the column VerifiedState to be enabled and editable. Is that possible in Flex datagrid.
If so, how can I achieve it.
You can do an ItemRenderer for the VerifiedState column, that won't show anything unless Item Status is Review Passed.
I agree use ItemRenderers, for any of the columns you want to disable. Then in your override of 'set data' just check if the row is in the correct state and add PropertyChange listeners to data obj (so when the object enters the correct state you can enable the column).

Resources