Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Datagrid: Modify Csv String Column



Hi, everybody...this is my first post!i'm creating a datagrid to read and publish data coming from other users in a .csv format...csv is like text (comes from excel), so the file is like:AAAAA;BBBBB;100;200;CCCVimporting the data i create the array pushing in the strings, where all the fields are strings (infact 100 and 200 are exported as string and not as number, but i can't change the csv files)so, sorting the columns, i'm using NUMERIC but this doesn't work...i think i'll be useful to refresh the data with a new array, like "AAAA";"BBBB";100;200;"CCCV", knowing where are the numeric columns...but i don't know how (or maybe there's a better solutions, the strings are about 2.000 with a dozen columns, so...)this is the class i'm using to load the csv:/* PUBLIC METHODS: onData() - Returns the raw data as a string. onLoad() parseCSV(rawData) - Takes the raw data as a string parameter and returns the data as an array PUBLIC PROPERTIES: columns [Array][Optional] - Default is to use the first row in the CSV file as the column headers qualifier [String][Optional] - If left blank, no qualifier will be used data [Array] - The data property is populated after the onLoad event has fired*/class CSV { // Variable to hold the data after the CSV data is parsed private var csvData:Array; // Declare the method that the user can override to get a callback when the data is loaded and parsed public var onLoad:Function; // The user can define this array prior to parsing the CSV data to manually define the column headers public var columns:Array; // The user can define this is the CSV data is using a qualifier public var qualifier:String = ''; function CSV() {} private function removeQualifier(originalString:String, qualifier:String):String { var modifiedString = originalString; if(modifiedString.charAt(0) == qualifier) { modifiedString = modifiedString.substring(1); } if(modifiedString.charAt(modifiedString.length - 1) == qualifier) { modifiedString = modifiedString.substring(0, (modifiedString.length - 1)); } return modifiedString; } public function load(csvPath:String):Void { // Use the LoadVars class to load in the CSV file as a String var csvLoad:LoadVars = new LoadVars(); csvLoad._parent = this; // Overwrite the LoadVar.onData method to get the file's contents before its parsed into the LaodVars class csvLoad.onData = function(rawData:String) { // Pass the raw data to the onData method this._parent.onData(rawData); } // Load the file based on the path passed in csvLoad.load(csvPath); } public function onData(rawData:String):Void { // Populate the private csvData parameter with the parsed CSV data csvData = this.parseCSV(rawData); // Call the onLoad method this.onLoad(); } // This method takes the raw CSV data as its parameter and returns the parsed data as an array public function parseCSV(rawData:String):Array { var ii:Number, columnArray:Array, rowObject:Object; // Create an empty array to hold the parsed CSV data var returnArray:Array = new Array(); // Determine the row delimiter for this file var rowDelim:String = (rawData.indexOf('
') > -1) ? '
' : (rawData.indexOf('
') > -1) ? '
' : ''; // Create the column delimiter based on the qualifier var columnDelim:String = qualifier + ';' + qualifier; // Split the raw CSV data into an array of the rows var rowsArray:Array = rawData.split(rowDelim); // If the Column array is not pre-defined by the user then the parser will automatically use the first row as the column headers if(!columns.length) { // Use the first row of the CSV string as the column headers columns = removeQualifier(rowsArray.shift().toString(), qualifier).split(columnDelim); } // Loop through the rows for(var i:Number = 0; i < rowsArray.length; i++) { // Split the row string into an array columnArray = removeQualifier(rowsArray[i].toString(), qualifier).split(columnDelim); // Make sure this row has the same number of columns as the column header array if(columnArray.length == columns.length) { // Create an empty Object to hold the row’s column data rowObject = new Object(); // Within the row we loop through the columns for(ii = (columnArray.length - 1); ii >= 0; ii--) { // Add the column data to the row object, using the column header as the object’s key rowObject[columns[ii]] = columnArray[ii]; } // We append the column object to the end of the main array returnArray.push(rowObject); } } return returnArray; } public function get data():Array { return csvData; } }



KirupaForum > Flash > Flash 8 (and earlier)
Posted on: 01-24-2008, 04:18 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

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

Only 2nd Column Of Datagrid Is Editable?
hi chaps!

i've got a datagrid that is populated from nested arrays in a local shared object. it works well. two columns are created and filled.
the problem is that i only want the user to be able to edit the second column cells.
is this possible?
maybe datagrid is the wrong component to use?

any help is appreciated!

cheers!
-----
**Flash 8 Pro***

[MX04] Add Column To Datagrid
I have a datagrid displaying items to be purchased. I want to add a column with a button (if possible) to let the user remove an item from the grid as if they changed their mind and don't want to purchase that specific item. Here are snippets of my code:


PHP Code:



var aItem:Array = new Array();
    aItem["PT1P1"] = {instance:PT1PPage1.AddtoCart, price:8, quantity:0};
    aItem["PT1P2"] = {instance:PT1PPage2.AddtoCart, price:8, quantity:0};
    aItem["PT2P1"] = {instance:PT2PPage1.AddtoCart, price:8, quantity:0};
    aItem["PT2P2"] = {instance:PT2PPage2.AddtoCart, price:8, quantity:0};

var totalPrice:Number;

//define button push functionality
for (var i in aItem) {
    var currentProduct:String = i;
    aItem[i].instance.id = currentProduct;
    aItem[i].instance.onRelease = function() {
        aItem[this.id].quantity++;//it has been added to basket
        updateDatagrid();//update datagrid
    }
}

function updateDatagrid():Void{
    totalPrice = 0;
    var aBasket:Array = new Array();
    for (var i in aItem) {
        if(aItem[i].quantity > 0 ) {
           aBasket.push({Product: aItem[i].instance.id, Quantity: aItem[i].quantity, Price: aItem[i].price * aItem[i].quantity });
           totalPrice += aItem[i].quantity * aItem[i].price;
        }
    }
    basketInfo.dataProvider = aBasket;
    basketInfo.vScrollPolicy = "auto";
    tTotal.text = totalPrice;
}




If I can't add a button to the datagrid to do this or you know of a different way to do what I want I'm all ears! Thanks!

[CS3] How Do You SetStyle To Each Column In Datagrid?
i have the following....


PHP Code:




//SET GRID PROPERTIES
import mx.controls.gridclasses.DataGridColumn;
var my_dg:mx.controls.DataGrid;

my_dg.setStyle("fontSize", "11");
my_dg.headerHeight = 20;
my_dg.setStyle("selectionEasing", Elastic.easeInOut);
my_dg.setStyle("selectionDuration", 500);


var dgc_pid:DataGridColumn = new DataGridColumn("pid");
dgc_pid.headerText = "SKU";
dgc_pid.width = 40;
my_dg.addColumn(dgc_pid);

var dgc_update:DataGridColumn = new DataGridColumn("updated");
dgc_update.headerText = "updated";
dgc_update.width = 80;
my_dg.addColumn(dgc_update);








I would like to give each column a background.. and one of them having bold text formatting

How Get A Datagrid Column Right-aligned
Hi,

I have a column with numeric values and i want to show this column as a right-aligned column, but the other columns (text) should have left-aligned. How can I reach this?

Please help
Thanks a lot

Datagrid Column Rollover, How?
Does anybody has idea how to get datagrid column rollover effect?
For example,
I want to change bckg color of 3rd column but it doesn´t work:
grid.getColumnAt(2).setStyle("rollOverColor", 0xFF3300);

Any help will be apreciated.

DataGrid 2 Column Sort
Hey gang.

I know the DataGrid can use the sort methods to do sorting but is there any way to sort by 2 columns? The first column may be user type, then second column may be username so I want all the user types to sort, then by username. Is this possible? Unfortunately the data is coming from a FlashCom Shared Object so its not a SQL query I can ORDER BY etc.

If the DataGrid cannot do this I may have to manually re-sort the Shared Object every time a change occurs etc?

Any help would be greatly appreciated.

Thanks and take care.

Space In Datagrid Column Name
Hello all,



I am populating a datagrid with a dataprovider array.

I added the column Names like "Phase Vol." , "Figure No." etc. by doing



Dg.addColumn ("Phase Vol.")

Dg.addColumn ("Figure No.");



now i want to asign a data in it by doing something like this

var item_obj:Object = { Phase Vol :"01", Figure No :30};
Dg .addItem (item_obj);



But the problem here is it does not take the space in property Name.. How do I keep my column Names value different?



Regards,
Mayur

Column Width In DataGrid
Hi,
I'm using a DataGrid to display certain tabular data, except a couple of columns that have buttons in them.
I've used CellRenderer API to display those buttons, but when I run the movie, upon resizing the column and making them small, the buttons spill over to the adjoining columns ...

Is there anyway to prevent this ?
I want the columns to be resizeable. Is there a minimum Column Width that I can specify ?

Help would be much appreciated

~TNE

How Do You Set Style In Each Column In A DataGrid?
i have the following....


PHP Code:

//SET GRID PROPERTIES
import mx.controls.gridclasses.DataGridColumn;
var my_dg:mx.controls.DataGrid;

my_dg.setStyle("fontSize", "11");
my_dg.headerHeight = 20;
my_dg.setStyle("selectionEasing", Elastic.easeInOut);
my_dg.setStyle("selectionDuration", 500);


var dgc_pid:DataGridColumn = new DataGridColumn("pid");
dgc_pid.headerText = "SKU";
dgc_pid.width = 40;
my_dg.addColumn(dgc_pid);

var dgc_update:DataGridColumn = new DataGridColumn("updated");
dgc_update.headerText = "updated";
dgc_update.width = 80;
my_dg.addColumn(dgc_update);



I would like to give each column a background.. and one of them having bold text formatting

DataGrid Component - Row And Column Colors
Hello,

This question deals with the DataGrid UI Component that comes with the Developer's Resource Kit.

What I need to do is display alternating color rows in a DataGrid, while keeping specific columns all a single color. I'm using the DataGridObject.alternateRowColors method to color the rows, and DataGridColumnObject.setStyleProperty( "background", theColor ) to change the column color.

Here are a couple of files that you can look at or download to see what I've got so far...

http://www.*****.com/DataGridTest.html
http://www.*****.com/DataGridTest.fla
http://www.*****.com/DataGrid.pdf (documentation for the DataGrid component)

As you can see, the red column gets overlaid by the alternating colors. What I would like to have happen is for the red to be on *top* of the alternating row colors.

Here's the exact code that is attached to the DataGrid object:

onClipEvent( load )
{
this.setColumns( "first", "second", "third", "fourth", "fifth" );
this.setEditable( true );

var dataArray = new Array();

dataArray[0] = { first:"Bill", second:"Jones", third:"123 St.", fourth:"City A", fifth:"43212" };
dataArray[1] = { first:"Ted", second:"Smith", third:"456 Ave.", fourth:"City B", fifth:"23454" };
dataArray[2] = { first:"Joe", second:"Test", third:"789 St.", fourth:"City C", fifth:"99898" };
dataArray[3] = { first:"Dave", second:"Gates", third:"876 St.", fourth:"City D", fifth:"76543" };
dataArray[4] = { first:"Betty", second:"Moore", third:"112 Blvd.", fourth:"City E", fifth:"98765" };
dataArray[5] = { first:"Sam", second:"Johnson", third:"984 St.", fourth:"City F", fifth:"77676" };

this.setDataProvider( dataArray );

this.alternateRowColors( "0x99FF99", "0x9999FF" );

this.getColumnAt(0).setStyleProperty( "background", "0xFF0000" );
}

Datagrid Column Index Question
Hi,

Is there any way to get the current column index of the datagrid component?

thankz

Tiago Janz Torre do Vale

Datagrid Column Editable Question?
I am using the datagrid and setting it to 'editable'. When I publish my file the first cell gets focus and erases the content. All that is left is a flashing cursor awaiting input. Is there a way to avoid this?

Thanks
MJ

Programmatically Set Datagrid Column Widths
I have a datagrid in my movie called summary_dg.
How would i set the column widths with actionscript?

UI DataGrid Component Column Editor
has anyone had problems with this extension?

DataGrid Column Editor

http://www.macromedia.com/cfusion/ex...011922&catid=0

for some reason or another after installing it, the wizard show no extension when a DataGrid has been choosen and highlighted on the stage?

any help is greatly apprciated.
Hector

Is It Possible To Align The Text In The Column Of A Datagrid?
I'm using the standard Flash MX datagrid component. There are several columns that contain numbers I want them to be right-aligned.

I've tried several different things including the following code:

Code:
newcolumn.align = "right";
Anyone have any ideas or know if this is even possible?

How Do I Get Value Of Cell In Column 3 Of The Selected DataGrid Row?
How do I get value of cell in column 3 of the selected dataGrid row?

For example, if someone selects a cell in row 2 of column 0, how can I get the value of the cell in column 3 of the same row?

I know how to get the value of a selected cell, I just can't figure out how to do the above. I'm using the following for that.

var myCellListener = new Object();
myCellListener.cellPress = function(event) {
var cell = "(" + event.columnIndex + ", " + event.itemIndex + ")";
var name = event.target.columnNames[event.columnIndex];
var item = event.target.dataProvider.getItemAt(event.itemInde x)[name];
_root.testText = "Value clicked: " + item + " _ " + "The cell at " + cell + " has been clicked";

}

Notifying Column Resizing In A DataGrid
Hello,
What's the notify event in a datagrid when we are resizing one column of it. I mean not columnStretch event because its trigger after the mouse up.
thank you

Icon In Column Header For Datagrid
I have googled myself to death and can't find a simple example. How can I use an icon instead of text for a column header in a datagrid. I tried creating a headerRenderer that just contains the image, but I couldn't get that to work. Is there a way to do it all inline?

Thanks!

Setting Datagrid Column Length
Hey all,

I have 2 columns in a datagrid. Is it possible to set the 1st column's length? If so, can anyone give me direction on how to do this?

Thanks!

Adding Datefield In Datagrid Column
I have a requirement to have datefield control in the datagrid column. I have to create the datagrid from actionscripts and also render the datefield from it. I tried using the datagriditemrenderer but its not working. Is there a sample code i can taken help from? Thanks in advance.

Showing HTML In DataGrid Column
This is driving me freaking nuts!

How the heck do you get a DataGrid to display HTML in the cells? I'm doing a databind from an XML file and it converts apostrophes to &apost; and it won't render it as HTML in the DataGrid cells. Any help would be greatly appreciated.

I've looked all over the Internet for help and haven't found any help.

Thank you very much.

Dynamic Datagrid Column Widths?
Has anyone coded a datagrid component so that the column widths adjust to match the length of the longest element in each one? I know how to set the width of a column to a specific pixel value, but how to go about calculating the width required for each cell? Obviously this depends on font choice and the number of characters I'm trying to display...

Any ideas?

How Do I Get Value Of Cell In Column 3 Of The Selected DataGrid Row?
How do I get value of cell in column 3 of the selected dataGrid row?

For example, if someone selects a cell in row 2 of column 0, how can I get the value of the cell in column 3 of the same row?

I know how to get the value of a selected cell, I just can't figure out how to do the above. I'm using the following for that.

var myCellListener = new Object();
myCellListener.cellPress = function(event) {
var cell = "(" + event.columnIndex + ", " + event.itemIndex + ")";
var name = event.target.columnNames[event.columnIndex];
var item = event.target.dataProvider.getItemAt(event.itemInde x)[name];
_root.testText = "Value clicked: " + item + " _ " + "The cell at " + cell + " has been clicked";

}

Accessing DataGrid Column Items....
I was wondering if anyone knew how to access column items...
ie if i made a column named "Info" and wanted to get the 5th item how would i go by doing so.. i though it was just an array something like this
my_dg[Info][i] were i is the index counter.. but that wasn't it.. i can get it to display the column name but thats about.. anyhelp is helpful


ps.. also had a question about flash and saving data locally...
i tried using MMSave(mystring,"/myfile.xml") but it seems that it always saves in the path C:Program FilesMacromediaFlash 8enConfiguration now i know i could just do MMSave(mystring,"../../../../../myfile.xml") and get it to save in the C: but i wanted it to be saved in the same path as the swf.. anyhelp with this would be helpful...

Thanks

[F8/AS2] Highlighting/Selecting Column In DataGrid
Hey everyone,
Here is a quick example I threw that shows how to highlight a column in the datagrid when you select a header. You can download the source here: http://www.kirupa.com/developer/flash8/code/VerticalColumn.zip

Here is a screenshot of how this looks:

I will write some more information about this later in a blog post, but I hope to find some time to write a tutorial outlining how to use the CellRenderer

Cheers!
Kirupa

Setting Datagrid Column Length
Hey all,

I have 2 columns in a datagrid. Is it possible to set the 1st column's length? If so, can anyone give me direction on how to do this?

Thanks!

Sorting Datagrid By Date Column
I've got a datagrid with a couple columns with dates (in DD/MM/YYYY string format) that I'd like the user to be able to sort on by clicking the column headers. Unfortunately, Flash treats the data as numbers and puts 01/01/2000 before 02/02/1900.

I've added a headerRelease listener to my datagrid that fires when the user clicks the column header. I've written a custom sort function called SortOnDate which I know works. I put the sort command into the headerRelease function as dataProvider.sort(SortOnDate).

If I trace the dataProvider, the data IS CORRECT. However, the data in the datagrid is still sorted incorrectly.

I'm assuming what's going on is the correctly sorted data goes into the datagrid, but the datagrid still applies the incorrect sorting to the data when it tries to display it since the column header is selected. Any solutions to this?

Showing HTML In DataGrid Column
This is driving me freaking nuts!

How the heck do you get a DataGrid to display HTML in the cells? I'm doing a databind from an XML file and it converts apostrophes to &apost; and it won't render it as HTML in the DataGrid cells. Any help would be greatly appreciated.

I've looked all over the Internet for help and haven't found any help.

Thank you very much.

DataGrid Dynamic Column Names
Hi, this is my first post here. I've researched elsewhere and posted in other forums about this question, with no luck. Hope I get better luck here.

My problem is I need to set and access DataGrid column names dinamically. That is, the col. names are not known at the time of writing the AS code.

I can set col names for example with:


Code:
var colNames:Array = new Array();
for (i = 0 ; i < data.length ; i++) {
colNames.push('col' + i) ;
}
my_dg.columnNames = colNames ;
That would produce a DG with cols col0, col1, col2, etc.

The problem is to acces them dinamically as well, for example with a for loop. The following code should get the values for each column, by name, at item in index 0:


Code:
for (x = 0 ; x < data.length ; x++) {
colName = eval('col' + x) ;
my_dg.getItemAt(0).colName ;
}
It doesn't works, clearly what is happening is it's trying to access column with name 'colName', which I don't want; instead I want that it gets columns with the value of that variable...

This are just examples of what I've done trying to get this; I have tried other approaches, with no succes. I hope someone can give me at least a clue of what to try instead. Thanks,

Alvaro Medina
http://www.escasoaporte.cl

Format Datagrid, Column Widths
Hi,

I'm having a tough time getting the datagrid to play nice.

cont_dg.columnNames=["Contacts", "Vendors", "idx"];
cont_dg.getColumnAt(0).width = 70;
cont_dg.getColumnAt(1).width = 200;
cont_dg.getColumnAt(2).width = 0;

This will fix the column headers and widths, but it throws the data out of wack.  If I don't use that code, I see data - when I use the code, no data appears.

Anybody know of any really good, clear tutorials for using the datagrid?

Column Headers On Datagrid Component
still having problems with tdk datagrid component.i have to hard code in the column names to fill the grid(creating new recordset)

i'm using flash remoting to return info from a database which i want to display this in the datagrid

i get a recordset back and the debugger shows in this format
List
    -(0)
       -eusfn   " info "
       -eusln   " info "
    -(1)
       -eusfn   "  "
       -eusln   "  "
etc.
or to reference it
     List(0).eusfn

eusfn, eusln is what i want to be the column header in the datagrid as that is the column header used in the database

has anyone got any ideas on what to do


Datagrid Column Header Does Not Sort
I created a datagrid that binds to a web service. Records retrieve fine. However when clicking on the column header in the datagrid, the data does not sort. I thought be default, it should sort. Is there something special that I have to code to sort?

Thanks.

Datagrid Get Value At Specific Column / Index
I would like to trace the value from a datagrid at a specific column / itemIndex. How can i do that? I´m using :


ActionScript Code:
trace(_root.pendentes.getColumnAt(1).getItemAt(2).label);


But it just gives me undefined.. Any help please?

Right Justify Column Data In Datagrid
Does anyone know how to right justify data in a column in a datagrid?

Thanks!

Flash Datagrid Want Empty Column Header
Hi,

Hopefully someone can provide me some guidance.
(Using Flash CS3 / Actionscript 3)

I'm using the datagrid component. I am doing this and its working fine.


Code:
// set column names
dg.columns = ["Other", "Address", "City", "State"];

// somewhere else in code
dg.dataProvider.getItemAt(i).Other = "change the left most cell value for this row";
I want to be able to do this while having the left colum header null or a space, but this doesn't work. How can I reference the column if the header is a space?


Code:
// set column names
dg.columns = [" ", "Address", "City", "State"];

// somewhere else in code
dg.dataProvider.getItemAt(i).Other = "change the left most cell value for this row";

I would appreciate any help I can get.

Thanks,
Eric

Datagrid Calculate Column - Some Useful Stuff, Some Help Needed
Hi - hope someone on my favourite site can help with this datagrid issue - I think it's just a small bit of code I've got to tweak. Might be some useful information to someone here anyway.

I've got a datagrid populated by info from mysql via amfphp.

I've managed to create a column that multiplies the qty and price fields:


Code:
root.dgCart.addColumn(column2);

var column2 = new DataGridColumn();
column2.headerText = "sum";

column2.labelFunction = customLabelFunction2;
column2.columnName = 'sum';

function customLabelFunction2(item:Object):Number {
// if (item == undefined) return undefined;
var sumtotal = round2D(Number(item.item_price) * Number(item.qty));
return sumtotal;
}


//helps to make decimals
function round2D (nr){
var tmp = String(nr)
var pos = tmp.substr(tmp.indexOf(".")+1)
if(tmp.indexOf(".")==-1) return nr+".00" //no decimals
else if(pos.length==1) return nr+"0" //1 decimal
else return Math.round (Number(nr) * 100) / 100 //2 or more
}
Now I'd like to get a total of all the items in the 'sum' column - the following code works to add up the 'price' column but the same approach doesn't seem to work for the 'sum' column - perhaps because the figures are generated by a function?


Code:
function getTotal(){
var totalPrice = 0;
for(var i=0; i<root.dgCart.length; i++) totalPrice += Number(root.dgCart.getItemAt(i).item_price)
root.txttotal.htmlText = "<b>Total:</b> "+ round2D(totalPrice);
}
If anyone here could shed the light, I'd be sooooo greatful!

[FMX04/F8] XML->Array->DataGrid... Column Issues...
First post here - believe me I searched high and low before asking this question...

I know a similar question has been asked many times before but I have a datagrid that is fed from XML that is pushed to an array. the XML contains an <id> tag for each firstChild.childNodes. The dataprovider for the grid is the aforementioned array.

Without overly complicating my explanation, I've taken all the paths to each child node and assigned it to a variable. I then just created an array and pushed each variable to it. The end result is that the datagrid shows only the information from the XML that I want it to show. I use a listener event to track when a user clicks on any row in the datagrid, at which point it captures the value in that child's <id> tag (a numerical value) and assigns that to a new "currentID" variable.

I then loop thru the original XML object searching for an <id> tag == currentID. This is working sweetly. When it finds the corresponding ID tag, it takes the paths to the other node info I want and sets it to some more variables. I then just info1.text = variable A, info2.text = variable B, etc.

Now I'd like to hide the <id> column from displaying in my datagrid. Problem is, when I remove it from the array, i no longer have a ID value to reference to go digging thru my nodes again after the fact. I guess I don't really mind it, but it's not something I really want in the grid. Tried the width thing - no luck. I need the ID info to load TO the drig, just not be displayed. If it doesn't make it to the grid, I have nothing to reference.

Any suggestions on keeping the ID column from displaying without throwing my reference out the window?

Also, how does .width() work? I mean, I know you just specify getColumnAt(-column index-).width = a given amount of pixels, but when I try and set the width of one column how do I know what other columns will be impacted? If you set one column width, do you need to go specify them ALL?

Sorry for the long winded post. Hope to get some answers though. Seems most other AS/Flash forums are nothing but repositories for unanswered questions.

v/r,
Steve

Sorting DataGrid By Column With Roman Numerals
Hi!

I'm really stuck with this problem, I would like to sort my DataGrid colums by a column with Roman numerals.
I use roman numerals only from II to XVII, so custom 'converter' will be enough.
When I don't use custom sort, and I click on roman numeral's header to sort my DataGrid the roman numerals sort like this:
"II"
"III"
"IV"
"IX"
"V"

Behaves like a String. This is all I accomplished on a way to create custom sort:


Code:

public function order(a, b):Number {

var name1:String = romToAra(a);
var name2:String = romToAra(b);

if (name1<name2) {
return -1;
} else if (name1>name2) {
return 1;
} else {
return 0;
}
}

public function romToAra(a) {
switch (a) {
case "II" :
a = 2;
break;
case "III" :
a = 3;
break;
case "IV" :
a = 4;
break;
case "V" :
a = 5;
break;
case "VI" :
a = 6;
break;
case "VII" :
a = 7;
break;
case "VIII" :
a = 8;
break;
case "IX" :
a = 9;
break;
case "X" :
a = 10;
break;
case "XI" :
a = 11;
break;
case "XII" :
a = 12;
break;
case "XIII" :
a = 13;
break;
case "XIV" :
a = 14;
break;
case "XV" :
a = 15;
break;
case "XVI" :
a = 16;
break;
case "XVII" :
a = 17;
break;
}
return (a);
}

function dataGridFunction(theData) {
var ref = this;
//
theRoot.dataGridMain.dataProvider = theData;


var listener_obj:Object = new Object();
listener_obj.headerRelease = function(evt_obj:Object) {
switch (evt_obj.target.columns[evt_obj.columnIndex].columnName) {
case "column1" :
theData.sortOn("column1", ref.order);
break;
}
};
theRoot.dataGridMain.addEventListener("headerRelease", listener_obj);


}
It doesn't work too good Is it possible to make it work?

Regards
Taurus76

Flex Advanced Datagrid Column Question
Hi All,

I was wondering if anyone knew how to have the columns in an AdvancedDatagrid expanded by default? At the moment part of my headers are been cut of:

For example: Price tar...

I want the columns to be expanded by default so that the full header name on all the columns are displayed! Any ideas anyone?

Thanks,
Derm

DataGrid Component Column Header Tooltips
Hi I am looking for a solution to complete within AS2 that allows a user to hover over a column header within a datagrid and a tooltip would pop-up.

I'm completeing a sports statistics sheet within Flash and I am obviously putting numbers in each column, else I would use the full column header but its just a number so I don't want to increase the width of the columns just for that.

If anyone knows of a way to make each individual column header able to pop up a tooltip plz post or recommend something. To give an example if it isnt obvious of what I'm trying to do

Lets say my Table looks like so

GP | G | A | +/- | %

have a tooltip for each one of those pop up with a tooltip

[F8] Datagrid In A Datagrid Column
Hello everyone,

Can someone give me a hint on how to solve the next problem ? I want to display a datagird (the 'child') in a column of another datagrid (the 'parent'). The content of the 1st 'child' datagrid is dependent on the value of the first column and row in the 'parent', etc. ect.
Example : first row in the parent-datagrid is a specific library, the child-datagrid in the first row shows the books available in this library. The second row in the parent-datagrid is another library, and the child-datagrid in the second row has to display the books available in this specific library.

The data to 'feed' both datagrid is coming from XML.
Someone out there who can give me a hint/link ?

I know this can be easily done using Flex/AS 3, but that is (sigh) not possible for this project....

Thanks in advance

Datagrid Calculate Column Total - Some Useful Stuff Here - Some Help Still Needed
Hi - hope someone can help with this datagrid issue - I think it's just a small bit of code I've got to tweak. Might be some useful information to someone here anyway.

I've got a datagrid populated by info from mysql via amfphp.

I've managed to create a column that multiplies the qty and price fields:


Code:
root.dgCart.addColumn(column2);

var column2 = new DataGridColumn();
column2.headerText = "sum";

column2.labelFunction = customLabelFunction2;
column2.columnName = 'sum';

function customLabelFunction2(item:Object):Number {
// if (item == undefined) return undefined;
var sumtotal = round2D(Number(item.item_price) * Number(item.qty));
return sumtotal;
}


//helps to make decimals
function round2D (nr){
var tmp = String(nr)
var pos = tmp.substr(tmp.indexOf(".")+1)
if(tmp.indexOf(".")==-1) return nr+".00" //no decimals
else if(pos.length==1) return nr+"0" //1 decimal
else return Math.round (Number(nr) * 100) / 100 //2 or more
}


Now I'd like to get a total of all the items in the 'sum' column - the following code works to add up the 'price' column but the same approach doesn't seem to work for the 'sum' column - perhaps because the figures are generated by a function?


Code:
function getTotal(){
var totalPrice = 0;
for(var i=0; i<root.dgCart.length; i++) totalPrice += Number(root.dgCart.getItemAt(i).item_price)
root.txttotal.htmlText = "<b>Total:</b> "+ round2D(totalPrice);
}


If anyone here could shed the light, I'd be sooooo greatful!

When Row In Datagrid Pressed/selected, Set Textfield.text To Column[1] Value?
I have 2 textfields and a Datagrid

My textfields are called details.details.text and details.name.text

my Datagrid has 2 columns ('Name' and 'Details')

When i click on the Row in the Datagrid, i would like the two text fields.text to become the values of the Rows selected in the Datagrid


Do you know how i would do this?

FMX04 - Datagrid, Locking HScrollPolicy On A Single Column. HELP
Hi!

I have searched all over for an example where you can lock/remove the horisontal scrollbar on a single column in a datagrid. The rest of the datagrid is scrollable, but the first is locked. Tricky feature that is far to advanced for the plain datagrid from Macromedia, but with all the experts on Flash out there, I hope someone has a solution for me.

Thanks!

Datagrid/dataprovider Changing Column Names (hash)
Ok I finally figured out all of my remoting issues with AMFPHP and AS3

I now have an array of column names: [id,group_fk,date_created,name,password]

And Arrays a bunch of arrays setup in the same order: [id, group_fk ,date_created, name, password ]

I want to be able to go through a dataProvider (or dataGrid) and just say myDg[0].id or myDg[0][id] rather than myDg[0][0] to get the id.

Any advice on what is the most efficient way to do this?

I tried just setting the columns of a datagrid to [id,group_fk,date_created,name,password] and then adding the dataprovider (which is just the bunch of arrays that match up in order).

Just looking for the best way to do this

Datagrid: Add Text Ellipsis (...) To Data Too Long For Column Field
I was wondering if anyone had any experience with cropping text and adding a text ellipsis (...) when text data is too long for a column field.

The actual adding of the ellipsis is obviously easy, but detecting when and exactly where to implement is whats got me stumped.

You can get the column's width, and probably the text label width in the cell field or a character count or some kind of work around to compare the two, but unless your using a monospace font, i'm hard pressed to find a good solution to adding this.

How To Paint Column Header And Not Whole Column
Hello to all. I am new to forum and new to flex. Have been senior delphi programmer for years and I am catching on quickly.

For training purposes, I am extending the DataGrid, and already added bunch of functionality.
I know how to paint rows and columns. However, I cannot find how to paint header of one column header in one color, other column header in other color, and not to affect whole column. I just want to paint where field name is, not data.
Sorry for being redundant, sometimes I have difficulty to explain what I want in english.

Thank you.
Emil

Dragging And Dropping From Datagrid To Datagrid
Yebo!

Is it possible to drag and drop items(cells?) from one datagrid to another?

Thanks
Renay

Copyright © 2005-08 www.BigResource.com, All rights reserved