Fix JSON type rendering. Fixes #1404

This commit is contained in:
Murtuza Zabuawala 2016-07-04 10:05:59 +01:00 committed by Dave Page
parent d4c3b1bcff
commit 3ee8861d44
2 changed files with 40 additions and 0 deletions

View File

@ -904,6 +904,40 @@
}
});
/*
* JSONBCell Formatter.
*/
var JSONBCellFormatter = Backgrid.Extension.JSONBCellFormatter =
function () {};
_.extend(JSONBCellFormatter.prototype, {
fromRaw: function (rawData, model) {
// json data
if(_.isArray(rawData)) {
var converted_data = '';
converted_data = _.map(rawData, function(data) {
return JSON.stringify(JSON.stringify(data));
});
return '{' + converted_data.join() + '}';
} else if(_.isObject(rawData)) {
return JSON.stringify(rawData);
} else {
return rawData;
}
},
toRaw: function (formattedData, model) {
return formattedData;
}
});
/*
* JSONBCell for backgrid.
*/
var JSONBCell = Backgrid.Extension.JSONBCell =
Backgrid.StringCell.extend({
className: "jsonb-cell",
formatter: JSONBCellFormatter
});
return Backgrid;
}));

View File

@ -1555,6 +1555,12 @@ define(
case "timestamp with time zone":
col_cell = 'datetime';
break;
case "json":
case "json[]":
case "jsonb":
case "jsonb[]":
col_cell = Backgrid.Extension.JSONBCell;
break;
default:
col_cell = 'string';
}