DataGrid Sorting questions 1/0 points to consider
Hi all
I have a problem that I can't find a way to fix. I use a datagrid that I pouplate by a XMListCollection based on XML data.
XML:
var prefs:XML = <files> <file name="@toto" favourite="1"/> <file name="@toto"favourite="0"/> </files>;
XMLListCollection
var xlc:XMLListCollection = new XMLListCollection( new XMLList ( prefs.file) );
MXML
<mx:DataGrid id="filesList" width="100%" height="100%" dataProvider="{xlc}"> <mx:columns> <mx:DataGridColumn width="25" dataField="@favourite"sortCompareFunction="favourite_sortCompareFunc"/> </mx:columns> </mx:DataGrid>
Sort to perform:
private function favourite_sortCompareFunc(itemA:Object, itemB:Object):int { var value1:Number = Number( itemA.@favourite ); var value2:Number = Number( itemB.@favourite ); if(value1 < value2){ var n:Number = -1; return n; } else if(value1 > value2){ return 1; } else{ return 0; } return 1; }
Once loaded, the data grid appears in a "normal state":
But if I try to sort the first column, it gets messy
I think it might be related to the fact that the data to be sorted is made only 0 and 1. But I can't imagine that this kind of situation is not repairable.
Any clue?
Thanks in advance for any advice,
Loïc
If I understand the problem, looks like you need a custom sort.
http://help.Adobe.com/en_US/Flex/using/WS2db454920e96a9e51e63e3d11c0bf66ce9-7fd6.html
Tags: Flex
Similar Questions
-
I have a column that contains moments from 10:00, 12:00, 22:30, midnight, 00: 00, 0 h 30 there and I want to sort them in such a way that 00:15 comes after 24:00, which is not case if I use sortItemsOn
datagrid.sortItemsOn ("Time");
How to order by time instead of the numeric value (not sure if I am not mistaken) lately?
Thank you
Yes, the representation of time in this XML file is bad enough. But assuming that there is no God, and deal with him - this is a point of Contact for you – you will need to adapt (or not) to your logic. I suggest you create a new FLA and experiment with this code in order to understand how it works.
The code below assumes that:
1 0005 comes 24 hours before 2405. If you need to just replace 24-00-0005 and 2405 are the same.
2. There is an instance of the DataGrid control on the timeline with a name of datagrid.
Code:
1 use your example of XML code.
2 header time implements click replacements - it sorts by column to actualTime which is hidden.
Read the comments.
import flash.display.*; import flash.events.Event; import fl.events.DataGridEvent; var xml:XML; init(); function init():void { writeXML(); populateGrid(); } function populateGrid():void { // limit columns to only three datagrid.columns = ["Title", "isbn", "Time"]; var date:Date = new Date(0); // this multiplier is reused to calculate minutes in milliseconds var minuteToMS:int = 60 * 1000; for each (var book:XML in xml.book) { for each (var time:XML in book.rented.time) { var value:String = time.toString(); // split time value in two parts with 2 digits each var timeParts:Array = value.match(/\d{2,2}/g); // set time on the Date instance based on hours and minute date.time = (timeParts[0] * 60 + timeParts[1]) * minuteToMS; // actualTime column is hidden but still can be used to sort on var row:Object = {Title: book.title.toUpperCase(), isbn: book.isbn, Time: timeParts.join(":"), actualTime: date.time}; datagrid.addItem(row); } } datagrid.sortItemsOn("actualTime", Array.NUMERIC); datagrid.addEventListener(DataGridEvent.HEADER_RELEASE, headerReleaseHandler); } function headerReleaseHandler(e:DataGridEvent):void { // if coumn header is Time if (e.dataField == "Time") { // if it is sorted in descending order if (datagrid.sortDescending) { // sort by actualTime in descending order datagrid.sortItemsOn("actualTime", Array.NUMERIC | Array.DESCENDING); } else { // otherwise sort in ascending order datagrid.sortItemsOn("actualTime", Array.NUMERIC); } } } function writeXML():void { xml = new XML(
Some title #1 xxxxxxxxx Some title #2 xxxxxxxxx -
DataGrid Sorting and itemClick event problem
Scenario:
I have a DataGrid. Click its item, it calls an itemClick event to perform certain functions. When I click on his head to sort before I chose to any element, it works fine. But if I chose point first of all, when I sort, it sort first and then go to run itemClick events functions.
I would like to know how only sort out anything that he chose point or not?
Thank you
When you click the column header, also, there's an itemClick. So, you will need to check the property rowIndex of the event parameter in your itemClick event handler. I think the rowIndex for the header row is 0, but it could be-1; you have to experiment.
-
Satellite P100-188: type the question - forgotten key & pointer jump
Hello
Bought my p100-188 week last to replace my toshiba PIII 2.66. After a week I noticed that when typing unless I press really hard that it does not record the keys. Also
the mouse pointer when it moves around the screen tends to move momentarily on a point, then jump past.All thought is appreciated.
Hello
I recommend you this announcement:
http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=14317Check it out. It describes a similar or the same question. It should help.
In addition, you should compare the version of the BIOS on the laptop with the version of the BIOS on Toshiba page. If there is a newer version so you can update. But be sure you use the good BIOS and the right update procedure. -
Oracle Express 11.2 sorting question
I am currently trying to learn the basics of Oracle Express, so I'm sorry if this is a really stupid question. I will now follow the tutorial and discovered that I can "t sort in descending order when you use the query designer. It won't let me select any other option but CSA under the sort type. I tried to use different browsers to see if that was the problem, but it's not. I know that I can just go and edit the SQL code to have it to do this, but it drives me crazy. Any ideas as to why the Query Builder doesn't let me choose a different sorting option?Hello
Have you tried with the tab key to move to the sort field and using the arrow keys to change the sort order.
Just a work around until find you a solution ;)Concerning
SANAE -
Hello
I have a problem when it comes to a datagrid with multiple sort fields. I have two fields A and B. B a numerical values. How can I sort B but also to modify the data in A since they are dependent on each other?
It comes to my datagrid
< s:DataGrid id = "rankinggrid" includeIn = "Ranking" x = "156" y = "84" width = "528" height = "229".
dataProvider = "{gridrank}" = "4" requestedRowCount >
< s:columns >
< s:ArrayList >
< s:GridColumn dataField = "sequrank" headerText = 'Sequence' sortDescending = "true" > < / s:GridColumn >
< s:GridColumn dataField = "coeff" headerText = "Coeffiecent" > < / s:GridColumn >
< / s:ArrayList >
< / s:columns >
< / s:DataGrid >
Basically, I want to sort coeff in desending order, but I want data in seqrank to move accordingly.
Thanks for your helpPS I am managing fill the datagrid control, so all that I need is to sort thanks
I think it has to do with the elements to a String and not digital, it must add the last parameter to make the Numeric type.
So, to see the valleys in ascending order, follow these steps.
var sortfieldRank:SortField = new SortField("Cost", false, true);
-
Custom (by date) in a DataGrid sort
So I have a data grid component connected to a provider of data like so:
var weekData:XML = / / some xml loaded and more soon...
var weekGrid:DataGrid = new DataGrid();
var dataProvider:DataProvider = new DataProvider();
for each {var entry: XML (in weekData)}
dp.addItem ({event:entry.title, date: FormatDate.format (new Date (entry.@startDate), 5), data:entry.@startDate});})
}
The title column, it's just what you think. The date Colum is actually a format such as may 2012 or 2013 Feb. And the "column" of data is not displayed in the dataGrid control that it is the 'key' to sort by date. It contains the getTime() value date as 1328515200000. So, who's going to date sort just a case of with the appropriate Array.DESCENDING Array.NUMERIC if necessary.
I found that if I do this:
weekGrid.dataProvider.sortOn ("data", Array.NUMERIC)
weekGrid.invalidate ();
It works and the grid is sorted - IF I have any other button to click to make this code executes.
I would like to forge with the click on the header of the grid event. As follows:
weekGrid.addEventListener (DataGridEvent.HEADER_RELEASE, sortDataGrid);
And I get the event and all, but obviously fireing off built-in sorting what happens after mine. And it is not what I want.
No idea how to stop this and allow my perferred sort taking place?
Found a smoother response.
weekGrid.addEventListener (DataGridEvent.HEADER_RELEASE, sortDataGrid);
{sortDataGrid(e:DataGridEvent):void funciton
var dg:DataGrid = e.target as DataGrid;
{if(DG.sortIndex==1)}
e.preventDefault ();
do what I want.
}
}
-
I seeks an achor point in the middle of an image for all executives leading up to a point, then have the anchor to another point, and then finally have the anchor switch back. I tried to do this with keyframes on the anchor, but the problem is that when I move the anchor point in a second keyframe (the first key frame with the anchor point original position), the position of the image change when I go back to frames before the second keyframe.
In other words:
I'm trying to move the anchor point without affecting the position of the image for this particular animation. Animate the anchor point seems to affect the position of the image. What can I do? Keyframe the position to stay still? Is there a better way?
The first question I have is why do you want to do this?
If you rotate or scale around the point of anchorage and you want to change the axis progresses the animation then maybe I'd understand, but this is the kind of a wonky workflow for me.
Whatever it is, try to add this expression to the value of your position:
apAdjust = anchorPoint - [width, height]/2; value + apAdjust
Change the anchor now now will not change the position of the layer. This works for 2D and 3D layers.
-
DataGrid Sorting, new high page elements
Hi all
I have the following datagrid
< mx:DataGrid id = "chatDG" width = "60%" height = "100%" x = "0" y = "0" fontSize = "25" variableRowHeight = "true" >
< mx:columns >
< mx:DataGridColumn headerText = "" dataField = "message" wordWrap = "true" / > "
< / mx:columns >
< / mx:DataGrid >That pulls information from a mysql database using the below php script
<? PHP
$hostname_conn = "localhost";
$username_conn = 'u ';
$password_conn = "pw";
$conn = mysql_connect ($hostname_conn, $username_conn, $password_conn);
@mysql_select_db ("DB");
$query = "SELECT * FROM THE CAT;
$result = mysql_query ($query);
While ($Row = mysql_fetch_array ($result))
{
echo "< cat > < message >. $row ['message']. "" < / message > < / cat > \n ";
}
? >and the following functions from flex
private void GetAllMessage (): void
{
getMessage.send ();
setTimeout (GetAllMessage, 1000);
}
private void viewMessageResult(evt:ResultEvent):void
{
chatDG.dataProvider = evt.result.chat;
}
[]] >
< / mx:Script >
< mx:HTTPService id = "getMessage" url = "getMessage.php" method = "POST" result ="viewMessageResult (event)" > "
< mx:request xmlns = "" >
< data > {dataDump} < / data >
< / mx:request >
< / mx:HTTPService >As it is at the moment of the new questions that are submitted to the database is displayed in the bottom of the datagrid, is there a simple and effective way to replace it? Then this new message, go to the top?
I have looked but can't seem to make it work =]
Where would understand the statement you mentioned?
"SELECT * CHAT ORDER BY Desc messageID.
If you could help I would be very grateful
assuming that your database now looks like this:
you will just place it where was your original query statement:
".$row['message']." \n"; } ?> -
Hey guys! Here's my question: I want to know how I can get a value in column of a datagrid selected by the mouse, as opposed to the whole line. My goal is to have a displayed image onMouseOver based on the element that the mouse is over.
Thank you.
You must have a handler ListEvent.
The ListEvent sent by the datagrid control will have the following properties:
columnIndex
rowIndex
example:
public void itemRollOverFunction(le:ListEvent):void {}
Alert.Show(le.) ColumnIndex.ToString () + the. RowIndex.ToString ());
}
It will be useful.
Thank you
Sirot.
-
Sort order incorrect in datagrid sort multiple columns
Hello
I'm a little confused about sort multiple columns in a datagrid. The following code sorts, but not the sort, I expect or what you are doing the thing about a coming O alphabetically before or after P. In my opinion, the code must sort stadt, vname by clicking on the city column, and name, the VNAME by clicking on the column name, but obviously he disobeys correctly? You see an error in the code or is this a bug?
<? XML version = "1.0" encoding = "utf-8"? >
"" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' layout = "vertical" >
< mx:Script >
<! [CDATA]
Import mx.collections.SortField;
Import mx.collections.Sort;
Import mx.collections.ArrayCollection;
Import mx.events.DataGridEvent;
var myData: ArrayCollection collection = new ArrayCollection (new Array () collection
{name: "Meier", vname: "Peter", City: "Bonn"},
{name: "Meier", vname: "Max", City: "Bonn"},
{name: "Meier", vname: "Olga", City: "Bonn"},
{name: "Meier", vname: "Peter", City: "Bochum"},
{name: "Meier", vname: "Susi", City: "Bochum"}
));
function mySort(event:DataGridEvent) {}
var mySorter: sort = new Sort();
Switch (event.columnIndex) {}
case 1:
mySorter.fields =]
new SortField ("name", true),
new SortField ("vname", true)
];
break;
case 3:
mySorter.fields =]
new SortField ("stadt", true),
new SortField ("name", true),
new SortField ("vname", true)
];
break;
}
myData.sort = mySorter;
myData.refresh ();
}
[]] >
< / mx:Script >
< mx:DataGrid dataProvider = '{myData}' headerRelease = "mySort (event)" >
< mx:columns >
< mx:DataGridColumn dataField = "name" headerText = "Name" / >
< mx:DataGridColumn dataField = "VNAME" headerText = "Vorname" sortable = "false" / >
< mx:DataGridColumn dataField = "stadt" headerText = "Stadt" / >
< / mx:columns >
< / mx:DataGrid >
< / mx:Application >Allright! So the column index begins with zero don't step one! It was the first.
Secondly, once you have defined your own sorter, you don't want the default behavior of the event to pass by so you will add
Event.preventDefault ();
just after myData.refresh (); line.
Give it a shot. should work.
HTH.
ATTA
-
Most recent iTunes, sorting Question
I'm sure it's something easy, and I'm right on it.
I use to be able to sort the albums, but "recent" or something to that affect where he would show about 20 or so of the most recent added to my collection, before going and alphabetical order the rest. Now with the new update, which seems to have disappeared. I hope that it is just a setting somewhere and not completely disappeared.
Apparently it is useful to post on this topic, LOL I found this now (:)
-
Question camera & Modem pointing Satellite M100
I have the Satellite M100 with Vista operating systems. When I changed the operating system a few days ago, there was a lot of drivers that have not yet been installed...
Then I downloaded & installed the drivers from this site...But even now, there are 2 drivers that might not be installed correctly: * POINTANT DEVICE * (I can't use the mouse, but my touch pad works) & * MODEM DEVICE ON HIGH DEFINITION AUDIO BUS * (I can not connect to the internet via dial-up modem)
Any ideas how to solve this problem? Thanx before...
Pointing device, I think you need to install the chipset drivers and check again, if you have installed any drivers, amenities and followed the installation instructions.
For Modem device, what you should you ensure you installed KB888111, KB835221. His work?
Installed all Windows updates? -
Question/the mouse pointer while playing music
When I play music or through Media Player or Stream on Acer Aspire 17.3 "4 GB 8.1 Windows laptop and move the pointer of the mouse while the music plays music drags or glitches while the mouse pointer moves, but will stop if I stop moving. Any ideas on how to solve this problem?
try to install this:
or try this:
CTRL-Alt-Del to load the Task Manager
Search in the background process to find "Intel (r) technology access Service."
Right click and choose "end task". -
Question on brush\pointer form
How do I get my pointer\brush to original - all of a sudden everything that I see a small sign + and can not see edge of brush, so I know what I am cloning or erasure. With the help of CC
Please check preset
Change the brush size and hardness in Photoshop CS6 "Julieanne Kost's Blog
How to change the clone stamp brush cursor from point crossed at a circle?
Concerning
Baudier
Maybe you are looking for
-
Fails to answer every time I try to attach any documents
When you attach it document window opens, but when you try to attach any document it comes up with does not
-
Linux for Portege 2010 SD card reader driver / controller
HelloI use Ubuntu Linux 6.10 on my Portege 2010. Things seem to work well, but I'm unable to download a driver for my SD card unit.Issues related to the:1. where can I find it?2 - is the SD card controller in this support of laptops SD Host Controlle
-
Harman kardon makes noises of cracking on my M40
Hello, I have M40 - 101, and my problem is my speakers crackling and noise burst (when using media player, winamp a bit higher volume). What can I do for this problem? is this hardware or software problem? Thanks for your help...(I also try Start/set
-
Opening Word, Excel and PowerPoint files in LabVIEW with digital signature of files
Hello I try to open Word, Excel and PowerPoint documents in LabVIEW (or were then converted into a format that can be opened). After the opening, to fill out checklists can insert a digital signature preset (possibly through an authorisation of user
-
April security updates Windows Vista caused laptop does not restart!
Update security for Windows Vista (KB3045685)Update security for Windows Vista (KB3045999)Update security for Windows Vista (KB3046306)Update security for Windows Vista (KB3046482) Message box, something went from an unusual way to term in the regist