我正在使用Array集合生成数据网格。生成数据网格时,会在网格末尾创建一些额外的行。我如何删除额外的行或阻止它们生成。
我生成网格的代码
private function createGrid(dataPrvdr:ArrayCollection, columnsValue:Array /*of Objects*/ = null):void
{
if (dataPrvdr && dataPrvdr.length)
{
includeInLayout = true;
var grid:DataGrid = new DataGrid();
if (columnsValue)
{
var cols:Array = grid.columns;
for (var i:int = 0; i < columnsValue.length; i++)
{
for (var prop:String in columnsValue[i])
{
//addDataGridColumn(prop, columnsValue[i][prop], grid);
cols.push(DataGridColumn(columnsValue[i][prop]));
}
}
grid.columns = cols;
}
grid.dataProvider = dataPrvdr;
grid.percentWidth = 99;
grid.styleName = "dataGridReport";
grid.setStyle("headerBackgroundSkin",DataGridHeaderBlueSkin);
grid.sortableColumns = false;
grid.editable = false;
grid.variableRowHeight = true;
grid.resizableColumns = false;
grid.rowCount = grid.dataProvider.length;
grid.headerHeight = 20;
grid.rowHeight = 16;
grid.verticalScrollPolicy = ScrollPolicy.OFF;
addElement(grid);
if (!grids)
grids = [];
grids.push(grid);
grid.addEventListener("multiLineLabelItemRendererHeightChanged", rendererHeightChanged, false, 0, true);
grid.addEventListener(FlexEvent.CREATION_COMPLETE, function (event:FlexEvent):void
{
grid.invalidateSize();
}, false, 0, true);
}
}
谢谢
答案 0 :(得分:1)
当您设置数据网格的height
属性时,它会覆盖rowCount
您可以将代码中的height
设置为:
grid.height = grid.dataProvider.length * grid.rowHeight + grid.headerHeight;
干杯,