Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] sort by date

Expand Messages
  • Satyam
    The recommended action, which I mentioned in my first reply to this mail, is to store the date internally as a native JavaScript Date object. Use a parser in
    Message 1 of 10 , Nov 14, 2008
    • 0 Attachment
      The recommended action, which I mentioned in my first reply to this
      mail, is to store the date internally as a native JavaScript Date object.

      Use a parser in the DataSource. The date parser provided with the
      DataSource uses the native date parser of JavaScript. If your date
      format cannot be read by that native parser, make your own. The
      datatable supports sorting all that the native JavaScript Array.sort
      function supports and that includes Date.

      None of the solutions suggested below will work if you enable cell
      editing for this cell. The calendar editor expects to find the date as
      a native JavaScript Date object.

      You don't need any formatter for dates as the built-in date formatter
      supports plenty of date formats through the dateOptions config attribute:

      http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html#config_dateOptions

      Satyam


      Philip Santosh Tellis wrote:
      > If I understand the problem correctly, you want to display the date in a
      > locale specific way, but sort it chronologically. By default, the
      > datatable only supports numeric and a case-insensitive string sort.
      >
      > There are several ways to get what you want. I'll list them here in
      > order of complexity (in my opinion):
      >
      >
      > 1. Always keep your data in a sortable format (eg: 20070301000000)
      > (YYYYmmddHHMMSS), and use a custom formatter to display the data in the
      > cell. Your custom formatter would be something like this:
      >
      >
      > function(elCell, oRecord, oColumn, oData)
      > {
      > var oDate = new Date(oData);
      > var sDate = YAHOO.util.Date.format(oDate, {format: "%b %e, %Y"});
      >
      > elCell.innerHTML = sDate;
      > }
      >
      >
      >
      > OR
      >
      >
      > 2. As Frank pointed out, add an invisible column which has the sortable
      > date in it, and set that column id as sortOptions.field for this field.
      >
      >
      > I don't have tested code to show you right now, but you would do
      > something like this:
      >
      > In your column definition, add a hidden field, and set sortOptions for
      > your main fields:
      >
      > var myColumnDefs = [
      > {key:"sdate", label:"Start Date", sortable: true, sortOptions: {field: "sdate_sort"}},
      > {key:"sdate_sort", hidden: true},
      > {key:"edate", label:"End Date", sortable: true, sortOptions: {field: "edate_sort"}},
      > {key:"edate_sort", hidden: true}
      > ];
      >
      >
      >
      > OR
      >
      >
      >
      > 3. Set "dynamicData" to true in the DataTable, and sort in the back end,
      > returning sorted results to your DataSource
      >
      >
      >
      > OR
      >
      >
      > 4. Implement a custom sorter for the column and assign it to
      > sortOptions.sortFunction for the column widget. (you can get the column
      > widget by calling getColumnById on the DataTable object).
      >
      >
      >
      >
      > On Wed, 2008-11-12 at 16:13 +0530, Rajendra Raskar wrote:
      >
      >> yes,
      >> Now I can sort column by date but it is in mm/dd/yyyy format or ytc
      >> format.
      >> ytc format =Sun Feb 4 00:00:00 UTC+0530 2007
      >> Still I am not able to sort column with locale specific format.(shown
      >> in attached image)
      >> e.g sep 1,2007
      >>
      >> --- On Tue, 11/11/08, Eric Miraglia <miraglia@...> wrote:
      >>
      >> From: Eric Miraglia <miraglia@...>
      >> Subject: Re: [ydn-javascript] sort by date
      >> To: ydn-javascript@yahoogroups.com
      >> Date: Tuesday, 11 November, 2008, 4:20 PM
      >>
      >> Rajendra,
      >>
      >>
      >> Check out the DataTable examples -- some of those show
      >> date-sorting, including:
      >>
      >>
      >> http://developer. yahoo.com/ yui/examples/ datatable/
      >> dt_basic. html
      >>
      >>
      >> Regards,
      >> Eric
      >>
      >>
      >>
      >>
      >> On Nov 10, 2008, at 11:01 PM, Rajendra Raskar wrote:
      >>
      >> >
      >> >
      >> > Hi,
      >> > In YUI datatable,i can sort any column but that is string.I
      >> > wanted to sort column by date.
      >> > How to do that.I think in column definition we have to do
      >> > something.
      >> > I tried parser:"date",formatter:"date",but it doesnt
      >> > work.can anybody help me regarding this..
      >> >
      >> > I am attaching image for reference..
      >> >
      >> > e.g
      >> > column def
      >> >
      >> > {key:"ReportName", sortable:true, minWidth:50,
      >> > resizeable:true, label:'<bean:message bundle="customDashb
      >> > oardResources" key="CWT_TXT_ RPT_NAME" />',width:170},
      >> > {key:"StartDate", sortable:true, parser:"date",
      >> > resizeable:true, label:'<bean:message bundle="customDashb
      >> > oardResources" key="CWT_TXT_ START_DATE" />',width:70},
      >> >
      >> >
      >> >
      >> >
      >> >
      >> > ____________________________________________________________
      >> > Add more friends to your messenger and enjoy! Invite them
      >> > now.
      >> >
      >> >
      >> > <sortdate.bmp>
      >>
      >>
      >>
      >>
      >> ______________________________________________________________________
      >> Add more friends to your messenger and enjoy! Invite them now.
      >>
      >>
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      > ------------------------------------------------------------------------
      >
      >
      > No virus found in this incoming message.
      > Checked by AVG - http://www.avg.com
      > Version: 8.0.175 / Virus Database: 270.9.2/1785 - Release Date: 13/11/2008 9:12
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.