动态改变DataGrid的栏2
动态改变DataGrid的栏,通过改变DataGrid的columns数组
效果:
你想通过一个checkBox选择情况来过滤 DataGrid或者List 组件中的内容
下面的例子告诉您怎么样过滤,主要使用ArrayCollection 类的 filterFunction 属性
<?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx = "http://www.adobe.com/2006/mxml" layout = "vertical" verticalAlign = "middle"backgroundColor = "white" >
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
private function toggleFilter():void {
if (checkBox.selected) {
arrColl.filterFunction = processFilter;
} else {
arrColl.filterFunction = null;
}
arrColl.refresh();
}
//过滤的主要函数
private function processFilter(item:Object):Boolean {
return parseFloat(item.value) == 0;
//返回值为0的对像,也就是过滤掉了值不为0的对像
}
//下面这个函数的作用是格式化显示 value 栏的数值,让它们都显示为保留两位小数点,如果不格式化的话,值为0的数据是不会显示出来的
private function value_labelFunc(item:Object, col:DataGridColumn):String {
return item[col.dataField].toFixed(2);
}
]] >
</mx:Script>
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
<mx:Object name="ColdFusion" value="0.00" />
<mx:Object name="Dreamweaver" value="0.12" />
<mx:Object name="Fireworks" value="1.01" />
<mx:Object name="Flash" value="0" />
<mx:Object name="Flash Player" value="-0.00" />
<mx:Object name="Flex" value="0.00" />
<mx:Object name="Illustrator" value="2.92" />
<mx:Object name="Lightroom" value="0.32" />
<mx:Object name="Photoshop" value="0.06" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:Panel status="{arrColl.length}/{arrColl.source.length} item(s)">
<mx:DataGrid id="dataGrid" dataProvider="{arrColl}" verticalScrollPolicy="on">
<mx:columns>
<mx:DataGridColumn dataField="name" />
< mx:DataGridColumn dataField = "value" labelFunction = "value_labelFunc" / >
</mx:columns>
</mx:DataGrid>
<mx:ControlBar>
<mx:CheckBox id="checkBox" label="Filter DataGrid" click="toggleFilter();" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>
For more information, see http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/.
原文地址:http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=8045
When I googled "sorting dates in a datagrid in flex" I found all sorts of outdated material, and some really complicated results, that i tried, but they just didnt happen to work in my situation… i’m not sure what everyone else was doing to create their dates, but I’ve heard a number of people saying it was very hard, or at least harder than they imagined…
that it is… a true statement in deed… just a note, but i havent even tried filtering on this… so forgive me if my solution wont work for it…
I kept battling this issue, and went back to one of the books i read "Adobe Flex 2 training from the source" and found an example in there, and built from it…
/////////////////////script block/////////// private function dateLabel(item:Object, column:DataGridColumn):String
{
return dateFormatter.format(item[column.dataField]);
}
/////////////////////script block///////////
<mx:DateFormatter id="dateFormatter"/>
<mx:DataGrid dataProvider="{acData}">
<mx:columns>
<mx:DataGridColumn dataField="name" />
<mx:DataGridColumn dataField="dob"
labelFunction="dateLabel"/>
</mx:columns>
</mx:DataGrid>
Please refer to the source links at the top and bottom of the entry for the real source… that code block is not safe to copy and paste and just work…. its just psuedocode.
If you notice I use a mx:DateFormatter id="dateFormatter" and by default the format is ‘mm/dd/yyyy’ so we dont need to supply a format for this example…
and in the script block there is a very simple function that just formats the label of the date column… and returns a string… and my sorting is working fine for now… please feel free to comment if you see any downfalls in what I have done…
原文地址:http://axel.cfwebtools.com/index.cfm/2007/8/24/Sorting-Dates-In-a-DataGrid-In-Flex-2
原文地址:http://axel.cfwebtools.com/index.cfm/2007/9/7/Using-a-tree-with-drag-and-drop-FROM-a-grid
开始之前要完成以下事情:
以下是最好的学习资源:
The data descriptor is something that some might say is misnamed. Because this little class, does so much MORE than describe data. You can use it to drill down into the node you choose, say… the selectedItem of your tree… myTree.dataDescriptor.isBranch(myTree.selectedItem)… I don’t think I fully understood the dataDescriptor until I read "Walking the tree" which is a great, great recursive function.
XML in actionscript 3.0 has some great built in functions like childen(), parent(), appendChild(), prependChild(), attributes()… among many many others, along with the e4x functions that comply with the ECMA Script standard, that allow you to filter data, and find things very very easily.
XML also already is heirarchichal by nature… so it only makes sense to use it in a tree structure, because it works very naturally with the tree because of it’s heirarchical nature.
One of the reasons I like the ArrayCollection vs. XMLListCollection is because an array collection can contain other ArrayCollections, and the XMLListCollection cannot. The XMLListCollection can contain XMLLists, but NOT multiple collections… so your limited by this, in the sense, that you can only have one filterFunction per XMLListCollection, as for an ArrayCollection you can have many if you embed array collections… I have never gotten this to work recursively, but theoretically, you could have a filter function filter a tree, and even dive into the nodes… (i’ve gotten it to work one level deep, into the tree’s branches, but never to go deeper, i do think i’m close, but no cigar)
I’ve been trying to work on this, but just havent had the time lately. eventually i’m gonna get it! and that will be a great day!.
A lot of people (including myself) that arent familiar with the dataDescriptor will use xml functions to recurse through the tree data, please… NOTE… YOU DONT HAVE TO DO THIS! the dataDescriptor is AWESOME! use it… i havent had it fail me yet…
Tree Control DataProviders > has information about finding and updating nodes, in both using xml dataproviders and arraycollections. Tree Drag and Drop Part 1 & Tree Drag and Drop Part 2 both have great info, but i did not seem to find any files with the whole source files released…
I can’t seem to thank this person named "Precia" for posting this code… it’s fantastic… THANK YOU THANK YOU THANK YOU! wish they had a blog they posted a link to.
This tutorial entry is absolutely fantastic for beginners, and it’s also a fantastic refresher for intermediate or advanced developers… I remember finding this back when i started researching the tree many projects ago… and using this entry as my starting and ending point, it explained everything i needed to do… I didnt event pay attention, but now i realize they even use the dataDescriptor in the code they’ve posted. But they don’t really focus on it as much as they should in my opinion.
I found this by looking up the Error #1009: Cannot access a property or method of a null object error while dragging and dropping with a tree… I absolutely love this post, and believe Jason did a terrific job of explaining the tree, and extending it as well. One thing I wanted to mention, that i’m sure he has found out since his post, is the following:
He states that when dragging and dropping with a tree, you can’t drop within a folder unless that folder is expanded, which is not necessarily true… you can do that, it takes a little bit of maneuvering but it can be done, take a look at the adobe quick start that i’ve linked to for using the tree.
I make use of the Spring Loaded Folder, and the flexcoders code that was posted, please take a look at the application i’ve linked to at the top and at the bottom of the page…
It’s getting super late, i’m writing this at 2am in a text file, and i’ll post it some time tomorrow, after i create the project and publish the source on the server at work…
Spring Loaded Folders: (Jason.Hawryluk@3gcomm.fr)
Peter Ent Tree Control DataProviders
Precia (app.developer) yahoo groups (am I within the folder or outside the folder?
Working with the tree adobe quickstart
LiveDocs DefaultDataDescriptor Documentation
drag and drop info flex docs 1: