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

Re: Datatable: Sort by Date

Expand Messages
  • claracruzz
    Many thanks Satyam, that did the trick. ... one ... be ... where ... in the ... numbers, ... won t ... work ... that. ... that ... assign a ... to ... will be
    Message 1 of 3 , Jan 6, 2009
      Many thanks Satyam, that did the trick.

      --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
      >
      > The way you are doing it seems correct to me, making the sort for
      one
      > column point to another column, as far as I know it should work. I
      > would only advise not to list the hidden column in the columns
      > definitions if it is never going to be shown, the data will still
      be
      > there if you list it in the fields, and you spare that narrow gap
      where
      > the hidden column would normally be.
      >
      > The best way to deal with any sort of data in the DataTable is to
      > convert everything to native JavaScript data types. Most features
      in the
      > DataTable expect dates to be native Date objects, numbers to be
      numbers,
      > not digits in between quotes and so on. If you manage to fix this
      > sorting issue, then you will find that the Calendar cell editor
      won't
      > work and the formatting facilities of the formatDate method won't
      work
      > either and you'll be constantly figuring out how to patch this or
      that.
      >
      > The best is to use a parser in the responseSchema.fields array so
      that
      > the data is converted to the right internal format right away,
      assign a
      > "date" formatter with the dateOptions configuration attribute set
      to
      > whichever format you want and then sorting will work nicely, cell
      > editing will be no problem and whenever you have to adapt you
      > application to support other languages, changing the dateOptions
      will be
      > all that you need.
      >
      > The built-in date parser uses the internal JavaScript Date.parse
      method
      > so if your date format is not amongst those it will naturally parse
      (and
      > dd/mm/yyyy is not amongst them) you have to set your own parser.
      It is
      > simply a function that will receive the unparsed string and has to
      > return the value to be stored. This is the one I use:
      >
      > myParseDate = function (oData) {
      > if (oData === undefined) return oData;
      > var parts = oData.split(' ');
      > var datePart = parts[0].split('-');
      > if (parts.length > 1) {
      > var timePart = parts[1].split(':');
      > return new
      > Date(datePart[0],datePart[1]-1,datePart[2],timePart[0],timePart
      [1],timePart[2]);
      > } else {
      > return new Date(datePart[0],datePart[1]-1,datePart[2]);
      > }
      > };
      >
      > It parses date in SQL format: YYYY-MM-DD hh:mm:ss, where the time
      part
      > is optional. Just move around the indexes for any order you care.
      > Remember subtracting 1 from the month.
      >
      > Satyam
      >
      >
      > claracruzz wrote:
      > > Hi All,
      > >
      > > I have a datatable, and I am sorting by date as per suggestion on
      this
      > > thread;-
      > > http://tech.groups.yahoo.com/group/ydn-javascript/message/40934
      > >
      > > As follows;-
      > > fields: ["Date","date_sort"]
      > > columns : [
      > > {key:"Date", sortable:true, sortOptions:
      {field:"date_sort"}},
      > > {key:"date_sort", hidden:true}
      > > ]
      > >
      > > The date_sort column has the value of Date column to
      milliseconds, such
      > > that Date:05/01/2009 = date_sort:1231113600000
      > >
      > > But it isn't working and I cannot figure out what I'm missing.
      The
      > > problem is that it shows the dates in the following order;-
      > >
      > > 05/01/2009
      > > 05/03/2009
      > > 06/01/2009
      > >
      > > Such that march 5th appears befor jan 6th, which is what it was
      doing
      > > b4 I applied the solution
      > >
      > > Any ideas please, on how to solve and a different solution
      perhaps?
      > >
      > > Please show example where possible, i'm not very good with wordy
      > > explanations.
      > >
      > > Many thanks
      > >
      > >
      > >
      > > ------------------------------------
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > > ------------------------------------------------------------------
      ------
      > >
      > >
      > > No virus found in this incoming message.
      > > Checked by AVG - http://www.avg.com
      > > Version: 8.0.176 / Virus Database: 270.10.2/1876 - Release Date:
      05/01/2009 9:44
      > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.