BackgridJS作者指出了正确的方向,我想出了这个解决方案:
var decimalFormatter = {
fromRaw: function (rawData) {
if(rawData == 0)
{
return '';
}
return rawData;
},
toRaw: function(data) {
return data;
}
};
/*
Create a new custom cell type and set a custom formatter.
Override the postRender() method in order to automatically select the
cell's contents for easier data entry when tabbing across rows.
*/
Backgrid.MyCell = Backgrid.StringCell.extend({
className: "my-cell",
formatter: decimalFormatter,
editor: Backgrid.InputCellEditor.extend({
postRender: function (model, column) {
if (column == null || column.get("name") == this.column.get("name")) {
// move the cursor to the end on firefox if text is right aligned
if (this.$el.css("text-align") === "right") {
var val = this.$el.val();
this.$el.focus().val(null).val(val).select();
}
else {
this.$el.focus().select();
}
}
return this;
}
})
});