How to clear the existing list data values - apache-flex

I would like to know how to delete(clear) the existing list data values before binding new values.
I'm using the list for binding data dynamically using http services. When I make a new call to the service, I want the exiting items to be flushed and bind the newly retrieved data to the same list. How can I achieve this?

You can explicitly set the dataProvider to null, or you can use removeAll() on the dataProvider.

You need not clear the data if you are binding httpService.lastResult to list.dataProvider. The data binding will create a new ListCollectionView object (ArrayCollection or XMLListCollection as the case may be) and assign it to list.dataProvider. Old data will be cleared automatically.

Related

JavaFX refetch observablelist from database

I need to show a custom made list of nodes from a database table that is frequently updated from external sources.
When changes are made to the database, the list needs to be updated on the screen accordingly.
For this I have implemented an ObservableList with an onChanged method that should check for changes and rebuild the custom list.
I my case the onChanged method will never fire when new data is added in the database, only when changes are made on the fly to the already defined ObservableList.
How can i let the ObservableList know when new data exists in the database ?
Thanks in advance!
Given your answer to jkaufmann it seems you need to change your logic.
Instead of rebuilding ObservableList each time you need to calculate the difference with new data and update ObservableList with new/removed data.

Why data binding does not remember the old values?

I have a classic ObjectDataSource and a ListView in my page. The List view just displays some data and when switched to edit template it allows the user to change the values. I want the user to edit just some values -- so I bind just these ones in the edit template.
The problem is that the other values suddenly turn to nulls or 0. I tried to bind all of the values at once and it works fine, but I cannot understand why the old/original values just disappear. Is there any way how to bind the old values?
Thanks for help.
The problem is, that only the data that is included into a round-trip to the server will be available in the postback. That includes all that that is bound to BoundFields, TemplateFields or if the Propertyname is included in the DataKey (or DataKeyNames, don't know right now).
The best approach to fix this, and to keep the overhead to a minimum is to add your primary key to the DataKeyNames collection. This allows you to have access to your custom object that contains an unique identifier and all properties that have just changes.
In your Update Method of the ODS (in your custom class) you now need to retrieve the old object by its unique identifier, manually assign the new values and saves your object back to the database

asp.net grid view save checked rows to datatable (paging is already done)

I implemented paging for one of my GridViews. Now I want that all checked boxes(which are kept in first column of GridView) to be inserted to Database. How can I achieve this? Please let me know.
I want to know how can I save the checked rows to the data table, and then re-bind to this temporary data table to grid view
If some body navigate back and uncheck check box for the row then how can i remove it again from the temporary datatable
Using a gridview and DataAdapters you can achieve this. Read more about updating data with DataAdapters here. To quote Microsoft on the use of DataAdapters:
You can use a data adapter to perform
the following operations:
Retrieve rows from a data store into
corresponding data tables within the
dataset.
To retrieve rows into a dataset, use
the Fill method on a data adapter
object (SqlDataAdapter,
OleDbDataAdapter, OdbcDataAdapter, or
OracleDataAdapter). When you invoke
the Fill method, it transmits an SQL
SELECT statement to the data store.
Transmit changes made to a dataset
table to the corresponding data store.
To transmit a dataset table of the
dataset to the data store, use the
adapter's Update method. When you
invoke the method, it executes
whatever SQL INSERT, UPDATE or DELETE
statements are needed, depending on
whether the affected record is new,
changed, or deleted.

Binding gridviews to viewstate until being able to write to database

I recently began working on a project which has many gridviews on a single page. During creation of a new record, the user needs to be able to add/remove/edit these gridviews and then save to the database at the end. The problem with this obviously is that there is no datasource to bind the data too until after its written to the database.
This data represents a 1..* relationship, which is why the gridview data cannot be written to the database until the parent record has been created first.
The best way I have found so far to solve this is to use viewstate. This solution however does not seem ideal to me. I am also forced to manually create the gridview functionality with OnDeleting, OnUpdating, etc so that I can manage the binding of the viewstate with the gridview.
Does anyone have any suggestions on a better way to manage this situation, it seems like it would be a common thing?
UPDATE:
Keep in mind this data needs to be around throughout postbacks.
Use a DataSet as an intermediate connection to your data source. Fill the DataSet with your data and then bind your GridView to the DataSet setting the GridView DataMember to the name of the table it is supposed to bind to.
As the user updates tables it will add/modify records in the DataTables in the DataSet. When the user is done editing and clicks "Save" your code can then update the database from the datasets, either automatically using a DataAdapter, or manually looking at the RowState of the rows in the DataTables.
Use a DataAdapter and a Dataset. Invoke the fillschema method in the adapter to create de metadata (cols, constraints, relations, etc) in the dataset. bind the data tables created to the different grid views. update manually cheking each row rowstate on each table or call the adapter's update method to do it automatically. If you do it automatically you need to define commands for insert, delete, and update in the adapter.

Flex Datagrid to Array?

I need to convert a datagrid table in Adobe Flex to an ArrayCollection. I was expecting to be able to loop through each row of a datagrid and write that to the Array collection, but the only method for accessing data in the datagrid that I can find is SelectedItem, which doesn't help me.
Obviously one could just copy the dataProvider for the datagrid, but my datagrid is editable and I need to store the state of the datagrid at any one time into a database. Can anyone recommend a method of doing this?
Much Appreciated
-Matt
If your DataGrid is:
<mx:DataGrid id="someDG" dataProvider="{this.provider}" />
Then check if this.provider is Array or ArrayCollection. If it is ArrayCollection then access it simply by:
var gotIt:ArrayCollection = this.someDG.dataProvider as ArrayCollection;
if it is an Array, then:
var gotIt:ArrayCollection = new ArrayCollection(this.someDG.dataProvider as Array);
Hope this helps.
You can do it by iterating over the fields in the columns, but you should be using the data provider. If the only place the state of your data resides is in a transient user interface control then you have to get it back into the domain objects and serialise them. Presumably each row in the datagrid is an object of some sort, in which case I would re-cast your problem as how to keep the edits in the datagrid and the domain objects in sync. If you crack that then there's no need to iterate over the datagrid.
The easiest way to solve the sync problem is to watch events on your editing renderers in the datagrid. When the grid contents change you automatically update the domain object.
What are your in place editors in the grid?

Resources