AS3数据网格 - 隐藏的行网格、数据

由网友(煮酒酿情话)分享简介:我用2组合框来过滤已通过CSV文件已填充数据网格。第一个组合框过滤柱和正常工作://监听器和功能时,选择了协议ID为agreement_cb.addEventListener(Event.CHANGE,协议);功能协议(事件:事件):无效{//取得的列数VAR列数:数= myGrid.getColumnCount...

我用2组合框来过滤已通过CSV文件已填充数据网格。第一个组合框过滤柱和正常工作:

  //监听器和功能时,选择了协议ID为
agreement_cb.addEventListener(Event.CHANGE,协议);
功能协议(事件:事件):无效
{
    //取得的列数
    VAR列数:数= myGrid.getColumnCount();

    对于(VAR我:= 0; I<列数;我++)
    {
        myGrid.getColumnAt(我)。可见=虚假的;
    }
    VAR得到columnnumber:数= agreement_cb.selectedItem.data;
    myGrid.getColumnAt(得到columnnumber)。可见=真;
    myGrid.getColumnAt(0)。可见=真;
    myGrid.columns [0] .WIDTH = 200;
}
 

但我不能找到如何获得相同类型的函数来隐藏所有的行,除非他们从第二个下拉(codes_cb)选择一个什么。

任何帮助是AP preciated ...

更新:

  loadedData = myLoader.data.split(/  r  N |  N |  R /);
    loadedData.pop();
    对于(VAR我:= 0; I< loadedData.length;我++)
    {
        变种rowArray:数组= loadedData [Ⅰ] .split(,);
        loadedData [I] = {SelectAgreement:rowArray [0],KSLTPROF0057:rowArray [1] .........};
    }
    loadedData.shift();
    myGrid.columns = [SelectAgreement,KSLTPROF0057,......];

    进口fl.data.DataProvider;
    进口fl.controls.dataGridClasses.DataGridColumn;

    myGrid.dataProvider =新的DataProvider(loadedData);
 

解决方案

A 的DataGrid 始终显示在其的dataProvider ,所以要隐藏行,你需要隐藏的数据对象。一些为的dataProvider 工作类小号有这个功能内置,使这个很容易(任何类实现的IList 即可被用作这些类的的dataProvider ),但 fl.data.DataProvider 是一个也没有。

所以,我会提供,如果你能同时​​使用,答案,我强烈建议使用 mx.collections.ArrayCollection 过的 fl.data.DataProvider

第1部分: fl.data.DataProvider

对于这个我假设你的 loadedData 数组是一个类属性,在函数没有声明。

 函数协议(事件:事件):无效
{
//您现有的code在这里
    VAR的dataProvider:DataProvider的= MyGrid.dataProvider为的DataProvider; //恢复数据提供器
    dataProvider.removeAll(); //删除所有行
    对于(VAR X:INT = 0,X< loadedData.length; X ++)
    {
        如果(loadedData [X] ==选择匹配)//在此处插入您的选择标准
        {
           dataProvider.addItem(loadedData [X]); //添加回dataProvider中
        }
    }
}
功能resetFilter():无效
{
    VAR的dataProvider:DataProvider的= MyGrid.dataProvider为的DataProvider; //恢复数据提供器
    dataProvider.removeAll(); // prevent重复
    dataProvider.addItems(loadedData); //重新加载所有行
}
 
如何进行网格设置

第2节: mx.collections.ArrayCollection

我的推理推荐,这是因为的ArrayCollection 已经有这样做没有丢失的物体失去范围数据的风险的功能外,还降低了$量C $ C /操作,你需要做的。要做到这一点,我们使用 ArrayCollection.filterFunction 和放大器; ArrayCollection.refresh()过滤看得见的阵列在不改变源代码。

 私人变种的dataProvider:ArrayCollection的=新ArrayCollection的(loadedData);
MyGrid.dataProvider = dataProvider中;
功能协议(事件:事件):无效
{
    //您现有的code在这里
    dataProvider.filterFunction = myFilterFunction; //使用我的过滤器
    dataProvider.refresh(); //刷新列表中可见使用新的过滤器/排序
}
功能resetFilter():无效
{
    dataProvider.filterFunction = NULL; //清除过滤器
    dataProvider.refresh(); //刷新列表中可见使用新的过滤器/排序
}
功能myFilterFunction(项目:对象):布尔
{
    如果(项目==选择匹配)返回true; //此处插入您的选择标准
    否则返回false;
}
 

在的filterFunction接受功能,并用它来测试每个对象的的ArrayCollection ,该函数返回一个布尔值,的是,显示该对象和为不diplay。

I'm using 2 comboboxes to filter a dataGrid that has been populated via csv file. The first combobox filters the columns and works fine:

//Listener and function for when the Agreement ID is selected
agreement_cb.addEventListener(Event.CHANGE, agreement);
function agreement(event:Event):void 
{
    //get the number of columns 
    var columnCount:Number = myGrid.getColumnCount();

    for (var i:int=0; i<columnCount; i++)
    {
        myGrid.getColumnAt(i).visible = false;
    }
    var columnNumber:Number = agreement_cb.selectedItem.data;
    myGrid.getColumnAt(columnNumber).visible = true;
    myGrid.getColumnAt(0).visible = true;
    myGrid.columns[0].width = 200;
}

But I can't find anything on how to get the same type of function to hide all of the rows except the one they select from the second drop-down (codes_cb).

Any help is appreciated...

UPDATE:

loadedData = myLoader.data.split(/rn|n|r/);
    loadedData.pop();
    for (var i:int=0; i<loadedData.length; i++)
    {
        var rowArray:Array = loadedData[i].split(",");
        loadedData[i] = {"SelectAgreement":rowArray[0],"KSLTPROF0057":rowArray[1] .........};
    }
    loadedData.shift();
    myGrid.columns = ["SelectAgreement", "KSLTPROF0057", ......];

    import fl.data.DataProvider;
    import fl.controls.dataGridClasses.DataGridColumn;

    myGrid.dataProvider = new DataProvider(loadedData);

解决方案

A DataGrid always shows all objects in its dataProvider, so to hide rows, you need to hide the data objects. Some classes that work as dataProviders have this functionality built in that makes this really easy (Any Class that implements IList can be operate as a dataProvider), however fl.data.DataProvider is not one of those classes.

So I will provide answers using both, if you can, I highly recommend using mx.collections.ArrayCollection over fl.data.DataProvider.

Section 1: fl.data.DataProvider

For this I'm assuming that your loadedData array is a class property, not declared in a function.

function agreement(event:Event):void 
{
//your existing code here
    var dataProvider:DataProvider = MyGrid.dataProvider as DataProvider;//recover the dataprovider
    dataProvider.removeAll();//remove all rows
    for (var x:int = 0; x<loadedData.length; x++)
    {
        if (loadedData[x] == "SELECTION MATCH") //insert here your selection criteria
        {
           dataProvider.addItem(loadedData[x]); //add it back into the dataProvider
        }
    }
}
function resetFilter():void
{
    var dataProvider:DataProvider = MyGrid.dataProvider as DataProvider;//recover the dataprovider
    dataProvider.removeAll(); //prevent duplication
    dataProvider.addItems(loadedData);//reload all rows
}

Section 2: mx.collections.ArrayCollection

My reasoning for recommending this is because ArrayCollection already has the functions to do this without the risk of data being lost by objects losing scope, it also reduces the amount of code/operations you need to do. To do this we use ArrayCollection.filterFunction & ArrayCollection.refresh() to filter the "visible array" without changing the source.

private var dataProvider:ArrayCollection = new ArrayCollection(loadedData);
MyGrid.dataProvider = dataProvider;
function agreement(event:Event):void
{
    //your existing code here
    dataProvider.filterFunction = myFilterFunction;//use my filter
    dataProvider.refresh();//refresh the visible list using new filter/sort
}
function resetFilter():void
{
    dataProvider.filterFunction = null;//clear filter
    dataProvider.refresh();//refresh the visible list using new filter/sort
}
function myFilterFunction(item:Object):Boolean
{
    if (item == "SELECTION MATCH") return true;//insert your selection criteria here        
    else return false;
}

the filterFunction accepts a function and uses it to test each object in the ArrayCollection, the function has to return a Boolean, true for "Yes, display this object" and false for "Do not diplay".

    Copyright 2016-2020 新思维的学习:AS3数据网格 - 隐藏的行网格、数据、All Right Reserved 浙ICP备20029812号-1