A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Datagrid column names

  1. #1
    Senior Member Shotsy247's Avatar
    Join Date
    Apr 2001
    Location
    Be there in a minute!
    Posts
    1,386

    Datagrid column names

    Hi All,

    I have a datagrid that I'm filling with data from an array. The array contains a bunch of objects with name value pairs. Each name value pair gets put in the appropriate column.

    For example, I have an object with the name value pairs: myArray = [{fName: "Bob", lName: "Dole"}, {fName: "Jim", lName: "Carter"}]

    These name value pairs will go into columns with the names fName and lName. These column names appear on the datagrid. I would like to change these column names to appear on the datagrid as "First Name" and "Last Name."

    I'm sure this is pretty simple, but I've never used the DataGrid component before. Please help.

    Thanks.

    _t
    I don't feel tardy.

  2. #2
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    give an nstance name to ur datagrid and then do the following

    instancenameofdatagrid.addColumn("First Name")
    instancenameofdatagrid.addColumn("Last Name")

    hope u r looking for this

  3. #3
    Senior Member Shotsy247's Avatar
    Join Date
    Apr 2001
    Location
    Be there in a minute!
    Posts
    1,386
    Thanks for the reply PSB. I saw that one and tried it, but was unable to assign values to the columns. How do I get the values from fName and lName into the "First Name" and "Last Name" columns? Perhaps that's the more appropriate question.

    Thanks.

    _t
    I don't feel tardy.

  4. #4
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    here is the code
    myDP = new Array({First_Name:"Chris", Last_Name:"Priceless"}, {First_Name:"Nigel",
    Last_Name:"Arc"});

    mydatagrid.dataProvider = myDP;

    give and instance name "mydatagrid" to ur datagrid or change it accordingly. and by the way u cant have space between the column name. if u give space then it takes it as seprate arguments. as far as i know. if u get some way to do so then do let me know.

  5. #5
    Senior Member Shotsy247's Avatar
    Join Date
    Apr 2001
    Location
    Be there in a minute!
    Posts
    1,386
    That's exactly where I ended up. I am able to add the columns, "First Name" and Last Name" with the spaces, by using the same code that you suggested:

    dataGrid.addColumn("First Name");

    but I'm unable to assign the value of fName from my object to the column. I can create a column named fName and that will take the values, but isn't to pretty for the end user to view, especially since many of my object names are very programatic, such as someValToUse. That works for a database and a variable name but not very human readable.

    Unless I'm missing what you are saying, it seems like I can't accomplish this, at least not easily. There should be a lable property for the column class.

    Since you seem to be the only person who will answer a question about a datagrid, I'll ask you a question I posted without reply.

    Do you know of any way to print the entire contents of a datagrid, especialy if the contents is larger than the datagrid, in other words the datagrid has scrollbars?

    Thanks for the help.

    _t
    I don't feel tardy.

  6. #6
    Junior Member
    Join Date
    Mar 2006
    Posts
    1
    Try this out...

    Keep your array the way you want it and simply change the header text of the columns once your DG has been populated:

    var myheadertext = my_dg.getColumnAt(0);
    myheadertext.headerText = "First Name";


    Repeat as needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center