sorting

Sorting datetime objects while ignoring the year?

I have a list of birthdays stored in datetime objects. How would one go about sorting these in Python using only the month and day arguments? For example, [ datetime.datetime(1983, 1, 1, 0, 0) datetime.datetime(1996, 1, 13, 0 ,0) datetime.datetime(1976, 2, 6, 0, 0) ... ] Thanks! :) ...

How do you specify node result order using XPath?

I have the following XML, which is generated by a 3rd-party library: <PhoneNumbers> <PhoneNumber Key="1">123-456-7890</PhoneNumber> <PhoneNumber Key="2">234-567-8901</PhoneNumber> <PhoneNumber Key="3">345-678-9012</PhoneNumber> </PhoneNumbers> The issue is that I should not depend on the values of the Key attribute (a) appe...

How do I implement sorting for a custom return type from a linq-to-sql query?

I am using a repository class with linq-to-sql as the objectdatasource for a (web) GridView. The GridView has to allow sorting on all columns. I have a working solution using this approach but I would obviously prefer to do this without a predefined list of sort expressions. public class TrailerMovementRepository { private TrailerMo...

sort arraylist in ascending order

hi, i have an arraylist of objects, each containing a year/month/day/hour property. what i'm ultimately trying to do, is create a new multidimensional array that contains a group of every object by incrementing hour. so for instance, an example of the final array i'd want is: array: [0] [0] 01:04:00, 4-10-09 [...

How can I use a Button control instead of LinkButton for gridview sorting in ASP.Net

I currently am using an ASP.Net gridview control and when a sortexpression is defined on the column, the column header is rendered as a linkbutton. I want to know if it is possible to convert that LinkButton to a Button control and preserve all the functionality. I cannot use TemplateColumns because I using DataControlField implementat...

Sort search results from MySQL by the position of the search query in the string using PHP

I want my search results to be in order of string position from smallest to greatest. For example, searching for "banana" returns: Babyfood, plums, bananas and rice, strained Bananas, dehydrated, or banana powder Bananas, raw Bread, banana, prepared from recipe, made with margarine CAMPBELL Soup Company, V8 SPLASH Juice Drinks, St...

Universal Sorting Function for PHP without the Locale Hassle

I asked a very similar question a while back and I was wondering if correctly sorting an array with UTF-8 chars got a little easier with the new improvements of PHP 5.3+. The solution provided in my previous question works, but I'm looking for a universal solution; one that doesn't depend on the locale specified - kind of what MySQL doe...

Sqlite query - order results with numbers last

Hey there, I would like to perform an SQLite query and order my results with numbers last. Eg: SQLite will ordinarily order results like this when I specify ASC on a text field: 0, 1, 2, A, B, C Whereas I would like this: A, B, C, 0, 1, 2 Any ideas? Is this possible? Thanks! Nick. ...

sort items in a dropdown list without the first item

I have the following code to sort the items in a dropdown list: function sortDropDownListByText(selectId) { $(selectId).html($(selectId + " option").sort(function(a, b) { return a.text == b.text ? 0 : a.text < b.text ? -1 : 1 })) } this works fine except in cases where, in my first item, i have a *"Please select and ...

Sort MySQL in Human

here's the code: $sql_namesResult = mysql_query("SELECT name FROM `scrimaprovedlist` ORDER BY `scrimaprovedlist`.`eorank`"); eo rank is a NUMERICAL value for a rank (general, colonel, ect). The problem is, when i set myself for 1, i am the top, but comes rank 10, instead of rank 2. how do i edit this to make it show in order: 1 2 ...

cocoa iphone fetchedResultsController sorting

Hey there, I'm working on an app that relies on a set of data that can be sorted in a variety of ways. I've got core-data setup. I have a fetch request that brings in all of the records. I've got a sort button on the left side of the nav controller. It brings up a modal view with table that has my sort options. when you change the ...

Is it possible to do a custom sort on a GridView

Hi, I need to sort a GridView (Not DataGridView, it's not the same thing) that is in need of a complex sort and I don't know how it can be done. I have two column, one containing a date and another containing a priority. If the date is lesser or equal to today's date. I want to order by priority first, then by date. If the date is gre...

Python: sort the list

I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row? EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I should join number and letters ...

Sorting only specific XML nodes

I need to sort only the <Transaction-Detail> nodes (by the <tran-id> child node) of the following file: <TransActDO clear="true" removed="false"> <stmt-reason-code>1001</stmt-reason-code> <Transaction-Detail clear="true" removed="false"> <txn-amt>788.20</txn-amt> <txn-description>New Purchase</txn-description> <tran-id>3...

Sorting by Random.Next()

In this question one of the suggestions is to sort a list by Random.Next(). I assume (maybe incorrectly) he's suggesting this public static IEnumerable<T> RandomSort<T>(this IEnumerable<T> items) { Random r = new Random(); var a = items.ToArray(); Array.Sort(a, (t1, t2) => (r.Next()%2==0)?-1 : 1); ...

In C#, is there a kind of a SortedList<double> that allows fast querying (with LINQ) for the nearest value?

Hi Stackers, I am looking for a structure that holds a sorted set of double values. I want to query this set to find the closest value to a specified reference value. I have looked at the SortedList<double, double>, and it does quite well for me. However, since I do not need explicit key/value pairs. this seems to be overkill to me, an...

How to sort randomly with CoreData

I am using NSFetchRequest to fetch some items, which could be sorted by Popular, or Random. Following the guides, I could sort the items by popularity easily using NSSortDescriptor. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"popularity" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc]...

JXTable listen to sort and sort a similar table the same way

I have a number of JXTables which all have the same columns (but different data). You can sort the data by clicking on one the header of one of the columns. What I want now, is that the other tables are sorted the same way when clicking on the header of one of the table. ...

xslt, sort by date - wrong date format, day first (ddmmyyyy)

Hello I would like to sort a list of 1500 files in XSLT 1. The list is similar to: 01052003.xls -> (translate to: 1th of May 2003) 25062004.xls -> (translate to: 25th of June 2004) 31032001.xls -> (translate to: 31th of Marts 2001) I can do a sort by name but since they are named ddmmyyyy sorting will be wrong. Can I somehow sort fi...

tableView sortDescriptorsDidChange: not getting called

Greetings, I have an NSTableView with two columns that works fine... except: If I set the sort descriptor for the table in Interface Builder, things work as expected and sortDescriptorsDidChange gets called as expected. If, however, I don't set the sort descriptors in Interface Builder and instead use this: [tableView setSortDescripto...