Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting datagrid mx 2004

Status
Not open for further replies.

jcaulder

Programmer
Apr 22, 2002
241
US
Hi,

I am bringing data from a database into Flash MX 2004 in the following manner:

XMLConnector --> Dataset --> Datagrid

Of course, the Datagrid is the only thing the end user sees on the form. Does anyone know how to go about formatting the column headers for the datagrid?

For example, I may be returning 10 fields from the database, some of which are "key" related and the user should not see. Also, the column names in the database are certainly not what I want the user seeing so I'd like to change them.

So basically, how do I:

1)Select only certain columns to display in the datagrid
2)Change the columns from the database column name to something meaningful to the end-user in the datagrid
3)Change the order of display in the datagrid

However this is done, it must not negatively impact databindings between form fields and the dataset.

I've looked but everyone seems to be using field names from the database as column headers in their examples. I did get something to work one time using the "formatter-->rearrange fields" option but it must not have been the correct way because it interfered with my databinding, specifically fields not included in the "formatter" would not receive updates.

Thanks in advance! I know it must be much simpler than I'm making it.

J
 
To change the order and to only have certain items display use a different dataset for the datagrid.

So let's say you are showing products and you only want to show a list of names in the datagrid, but then you want to show a detail when the grid item is clicked.

You would use one dataset for the details, and one for the datagrid display (which contains only the items that you want in the order you want them). You bind both datasets to the SelectedIndex of the datagrid, so your display will show the detailed information (which is bound to the detail dataset) based on which grid line is selected.

To rename the fields you can add an event listener to the dataset and rename the fields once the set is loaded.

Code:
import mx.controls.gridclasses.DataGridColumn;
dataListener = new Object();
dataListener.afterLoaded = function() {
	//rename the columns
	data_dg.getColumnAt(0).headerText = "New column 0 Name";
	data_dg.getColumnAt(1).headerText = "New column 1 Name";
	data_dg.getColumnAt(2).headerText = "New column 2 Name";
	data_dg.getColumnAt(3).headerText = "New column 3 Name";	
};
data_ds.addEventListener("afterLoaded", dataListener);

Hope it makes sense.

Wow JT that almost looked like you knew what you were doing!
 
Thanks for the post pixl8r!

I guess I could then use a 'removeColumnAt' command to get rid of columns I don't want displayed.

I'm not sure my post was completely clear. My data structure from the database is similar to:

Patient_Id
Patient_Fname
Patient_Lname
Patient_Sys_Id

I want all of these columns available to the form through the dataset but only want to display the Patient_Fname and Patient_Lname in the datagrid with the header 'First Name' and 'Last Name' and perhaps change the order in which they appear in the grid from the order they are in the xmlconnector and dataset.

My only option is to go through programmatically adding, removing and renaming columns in the datagrid? I was hoping there was an easy way to accomplish this, perhaps with the formatter-->rearrange fields. I still haven't seen an easy way to reorder the fields in the datagrid.

Thanks for the reply!

j
 
As I said use two different datasets (bound to the same XMLConnector). 1 contains the schema for Patient_Fname and Patient_Lname. The other contains the schema for all of the fields. Bind the selected index of the datagrid to the selected index of both datasets. Bind your text fields to the dataset with the details.

Hope that's clearer. :)

Wow JT that almost looked like you knew what you were doing!
 
Oh, I see what you're saying. The order the columns appear in the datagrid are actually determined by the order they appear in the dataset's schema. So I can change the order of the dataset schema to change the order they appear in the datagrid. And to get rid of columns, I can either programmatically do it using the removeColumnAt command or either use a second dataset, add only the columns I want to see in the datagrid and then link this to the datagrid while using the initial dataset as the primary for linking to the actual data fields.

Thanks for taking time to retype it! It's very clear now.

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top