-
Notifications
You must be signed in to change notification settings - Fork 323
Object 1361561820000 has no method 'trim' #141
Comments
The datetime cells don't accept Date objects, you have to use ISO-8601 strings as your grid values. |
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! |
@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... |
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 |
Fixed in 05d7e81 |
Glad you did it, I really did'nt have the time this week to make this the way you do! |
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
👍
The text was updated successfully, but these errors were encountered: