Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Object 1361561820000 has no method 'trim' #141

Closed
wd40dw opened this issue Apr 25, 2013 · 6 comments
Closed

Object 1361561820000 has no method 'trim' #141

wd40dw opened this issue Apr 25, 2013 · 6 comments

Comments

@wd40dw
Copy link

wd40dw commented Apr 25, 2013

Hi there,

Im new to backGrid and im very impressed with what it can do so far.

I have successfully got some data from my Database back to my web-app in JSON and all renders ok with the exception of a date column which will throws and error Object 1361561820000 has no method 'trim' Heres is the column:

var columns = [{
name: "dateTime",
label: "Date/Time",
cell: 'date'
}];

This will render ok on the page when cell is set to 'string' but obviously this doesnt display in date format..

Is there anyway around this?

Previously i used a standard html table and parsed the date column with: $.format.date(get('dateTime'), 'dd/MM/yyyy hh:mm:ss' but i seem unable to apply this now,

Any help much appreciated

👍

@wyuenho
Copy link
Contributor

wyuenho commented Apr 25, 2013

The datetime cells don't accept Date objects, you have to use ISO-8601 strings as your grid values.

@martinlie
Copy link

I managed to make an extension wich fits my needs for both displaying and editing with simple validation. I am unsure of how I could contribute this code as an extension to the framework, but I put it here for convenience:

var DatetimeISOFormatter = Backgrid.DatetimeISOFormatter = function (options) {};
DatetimeISOFormatter.prototype = new Backgrid.CellFormatter();
_.extend(DatetimeISOFormatter.prototype, {
    _isValidDate: function(d) {
          if ( Object.prototype.toString.call(d) !== "[object Date]" )
              return false;
          return !isNaN(d.getTime());
      },

      fromRaw: function (rawData) {
          if (_.isNull(rawData) || _.isUndefined(rawData)) return '';
          return new Date(rawData).format("isoDate"); // http://blog.stevenlevithan.com/archives/date-time-format
      },

      toRaw: function (formattedData) {
          var d = new Date(formattedData);
          if (!this._isValidDate(d)) return undefined;
          return d.getTime();
      }
});

var IsodateCell = Backgrid.IsodateCell = Backgrid.DatetimeCell.extend({
      className: "isodate-cell",
      includeTime: false,
      formatter: DatetimeISOFormatter
});

You could use a Date formatter like the one at http://blog.stevenlevithan.com/archives/date-time-format or your own.

To use it, I just did:

this.grid = new Backgrid.Grid({
              columns: [{
                  name: "performed",
                  label: "Performed date",
                  cell: "isodate"
              },
...

Hope this helps!

@wyuenho
Copy link
Contributor

wyuenho commented Apr 28, 2013

@martinlie see CONTRIBUTING.md. I try to enforce the policy that every PR must come with tests, but that hasn't been too successful. Let me know if you need help. I also opened a new issue #145, so your commit message should probably say something like Fix #145 blah blah blah...

@wyuenho
Copy link
Contributor

wyuenho commented Apr 28, 2013

BTW, if you do decide to contribute. I'd like to see an implementation that doesn't use any external libraries as this change will largely be addressed in the core datetime formatter. You should be able to put the timestamp into a Date object and construct an ISO-8601 string that works in IE8. You can then just pass the ISO-8601 string to _convert.

@wyuenho
Copy link
Contributor

wyuenho commented May 3, 2013

Fixed in 05d7e81

@wyuenho wyuenho closed this as completed May 3, 2013
@martinlie
Copy link

Glad you did it, I really did'nt have the time this week to make this the way you do!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants