PDA

View Full Version : Dynamic datagrid text cutoff



neoviper
January 9th, 2010, 11:30 PM
I'm trying to bring in data from an xml file, and populate a datagrid with it. I've got that working just fine, but all the columns are spaced evenly, and will not extend it if the content in the rows is too long. I found an example of it that would be acceptable, if it was doable in actionscript 3 alone, unfortunately this example uses flex. It's near the bottom of the page.

http://blog.flexexamples.com/2007/07/23/creating-multi-line-data-grid-rows-with-variable-row-heights/

That would really be perfect, dynamically going multiline and increasing row height when it needs to. I found an adobe article on making it multiline in just flash, but its completely static. I've been able to reference the text width through the cellrenderer class, but I can't get access to the datagrid from there. If I could get the textField width and then use that to determine column width, that would be incredible.

Failing all of that, I'd be happy to know of any alternatives, or if It's just a fruitless endeavor to begin with.

GarFonz
January 10th, 2010, 01:05 AM
this is seemingly inefficient, and surely there is a more elegant solution, but if you are in a bind, you could fill a Textfield and gleen the properties you need from there...

neoviper
January 10th, 2010, 10:25 PM
I could fill a text field, but that would only get me the width of that particular string, I'm expecting to have a great many strings that could populate the datagrid. For the moment I can just set the width based on the text I have now, but that will at some point in the future not be good enough. Anyone have any idea how I could make that example I posted without flex?

GarFonz
January 11th, 2010, 01:01 PM
Salutations neoviper! I have to switch my focus to another project, but I have found a way to access the textfield in the column of the datagrid. Unfortunately, I have not produced a complete reproduction of the example you provided, and the following script is not complete but it is a start.

var dg:DataGrid;
var cr:CellRenderer = new CellRenderer();
cr.textField.wordWrap = false;
cr.textField.multiline = true;
cr.textField.autoSize = "left";
dg.columns[0].cellRenderer = cr;
dg.addEventListener(DataGridEvent.COLUMN_STRETCH, col0);

function col0(e:DataGridEvent):void{
cr.textField.wordWrap = true;
cr.textField.width = e.target.columns[e.columnIndex].width - 6;
//cr.textField.y = 0;
cr.height = cr.textField.height;
dgCol1.cellRenderer = cr;
dg.columns[0] = dgCol1;
} I believe that you should check into ListData and how it can work with CellRenderer in order to fill the columns properly because in my test only one row would fill.

neoviper
January 12th, 2010, 09:31 PM
That should get me started fine, many thanks!