suki2.jpg

« 8Gb memory in Laptop | Main| Doing Scheduled agents When not on a Domino server »

After the honeymoon, Tip 1

QuickImage Category Flex Domino

Its been about 2 months since i started using adobe flex in billable anger, and even the best platform looses some of its ability to escape criticism in that time, flex however is proving to be everything that I had hoped for, but you still bump into the odd thing that domino does much better, so I'm doing a series of tips and tricks to help you get everything from both systems (especially when used together).

Todays tip is sortable date columns in flex data grids

Flex data grids are a wonderful thing, with easy sorting and sizeable columns and such, but one thing sucks on them, and that's the fact that they only do TEXT sorting, dates are just treated like text which means that all of the common date formats wont sort correctly, Booooo!, but we can fix that surprisingly easily

First you want to output your date data from notes in YYYYMMDD format, why?? because this formats displays the same when sorted textually or chronologically

so in a view that would be (its a bit long as we need to pad the short days/months (thanks to Ben Poole for pointing this out))

***edited by popular vote to a shorted version***

@Text(@Year(LossDate)) + @Right("0" + @Text(@Month(LossDate));2) + @Right("0" + @Text(@Day(LossDate));2)

if your using a web service to return that value, the Java code would be

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

Item dateitem = doc.getFirstItem("DateIWant");
DateTime notesdate = dateitem.getDateTimeValue();

DateFormat dateFormatordered = new SimpleDateFormat("yyyyMMdd");

String UpdDtSort=dateFormatordered.format(notesdate);

if you using lotusscript for you webservice then your on your own!!.

Now into flex and define a "Dateformater", this is my personal fav date format (is it sad that i have one) and produces dates like "Tue May 04 2009", which i find removes many problems with international formats causing confusion.

<mx:DateFormatter id="dateFormatternice" formatString="EEE MMM DD YYYY"/>

Next you will need your actual datagrid (which you will already have if you have discovered this problem).  

<mx:DataGrid width="740" height="126" x="10" y="34" id="datesortview" dataProvider="{mynotesview}" fontFamily="Arial">
        <mx:columns>
                <mx:DataGridColumn headerText="Description" dataField="Desc"/>
                <mx:DataGridColumn headerText="Updated Date" dataField="UpdDtSort" labelFunction="dateLabel"/>
                </mx:columns>                                        
</mx:DataGrid>

You will notice the "labelFunction" at the end of the date column, that calls the following function (and passes the parameters automatically).

private function dateLabel(item:Object, column: DataGridColumn) : String {
    if (item[column.dataField] != null) {
       var TempDate:Date = DateField.stringToDate(item[column.dataField], "YYYYMMDD");
            return dateFormatternice.format(TempDate);
    } else {
       return "";
    }
}

This basically just takes in each value in the column, converts it to a date using a mask, formats to a pretty format and returns it back to the column. it is MUCH faster than attempting a code based sort solution (as some people use in flex using "sortCompareFunction" on a datagrid).

your column now has 2 values the underlying data format in the happily sortable "20090504" and the label format that the user sees in the format "Tue May 04 2009", yet again a feature we took for granted in notes requires a bit of coding to get it in other platforms.
Bookmark and Share

Comments

Gravatar Image1 - I haven't done any Flex yet, but thanks for sharing your experience.

On formatting the date with formula, here is a shorter version that I've used:

@Text(@Year(LossDate)) + @Right("0" + @Text(@Month(LossDate));2) + @Right("0" + @Text(@Day(LossDate));2)

Gravatar Image2 - Cool, thanks for that (i learn something new each day and am always up for a better way of doing things)

Gravatar Image3 - Mark - at what point did you get a perfomance hit with the date compare function?

Currently have about 300 - 400 rows in the datagrid and not seeing any performance hit - not compared to Notes 8.5 anyway Emoticon

By the way your not mad having a favourite date format, mines DD-MMM-YYYY

Mark

Gravatar Image4 - ISO 8601.

That is the name of the document regulating the international ISO date format, it is YYYY-MM-DD.

It has the advantage of being alphabetically sortable, more readable than your suggestion, AND a lot of programs will recognise immediately that this is a date (MS Excel comes to mind).

Just my 2 cents

Andrew

Gravatar Image5 - @4 ISO 8601, its a good an logical point, and a nice one if i get the chance in the future, i have however found that "EEE MMM DD YYYY" works well with users (ie the "dont bother doing the security, but can i have that in pink" lot), but ISO8601 is cool to know

Gravatar Image6 - @ 3 i noticed a 0.5 second hit at about 2500 documents between the grid with the label function on and off (on a fast link to a German website), does that help

Gravatar Image7 - @5

I was suggesting ISO as your format for sorting, not the user display format.

In my previous life as a mechanical engineer, I had to struggle with US imperial units. Disaster! We usually converted immediately to SI, did the calculations, then reconverted to US units.

Internationalization tends to be the last thing american programmers do... The number of times I have not been able to fill in an international address because of some silly "Please enter the state you live in" with a dropdown of US States... Duhh

Andrew

Gravatar Image8 - @7 fair point, after all the US is the only country in the world Emoticon

Gravatar Image9 - Thought I'd post this as I'm doing it right now... If you need to do number padding in Java (5+) then it's very straightforward:

[code]String.format("%02d", YOUR_INTEGER_GOES_HERE);[/code]

Smashing (shame about the UBB code not actually, uh, working)

Gravatar Image10 - Thanks for help! This is just what I was looking for!

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Avalable for on site contract in

 

Hire Me

Directly:

Curriculum Vitae

As a member of:
ldc_badge.gif

LDC Tshirts

Contact My Grubby Hide

Skype Linkin Main Me Twitter

Common sense for the recession

keep_calmblog.jpg