Skip to content

Commit

Permalink
Enable to set formatter and editor on the same cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej Kumor committed Mar 19, 2013
1 parent cbf15b2 commit ce06c38
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,13 @@ function(kernel, declare, listen, has, put, List, miscUtil){
}else if("field" in column && column.field != "_item"){
data = data[column.field];
}

// Support formatter, with or without formatterScope
var formatter = column.formatter,
formatterScope = self.formatterScope;
if(formatter){
td.innerHTML = typeof formatter === "string" && formatterScope ?
formatterScope[formatter](data, object) : formatter(data, object);
}else if(column.renderCell){

if(column.renderCell){
// A column can provide a renderCell method to do its own DOM manipulation,
// event handling, etc.
appendIfNode(td, column.renderCell(object, data, td, options));
}else if(data != null){
td.appendChild(document.createTextNode(data));
}else {
defaultRenderCell.call(column, object, data, td, options);
}
}, options && options.subRows);
// row gets a wrapper div for a couple reasons:
Expand Down Expand Up @@ -502,11 +496,24 @@ function(kernel, declare, listen, has, put, List, miscUtil){
}
});

function defaultRenderCell(object, data, td, options){
if(data != null){
if(this.formatter){
// Support formatter, with or without formatterScope
var formatter = this.formatter,
formatterScope = this.grid.formatterScope;
td.innerHTML = typeof formatter === "string" && formatterScope ?
formatterScope[formatter](data, object) : formatter(data, object);
}else{
td.appendChild(document.createTextNode(data));
}
};
};

// expose appendIfNode and default implementation of renderCell,
// e.g. for use by column plugins
Grid.appendIfNode = appendIfNode;
Grid.defaultRenderCell = function(object, data, td, options){
if(data != null){ td.appendChild(document.createTextNode(data)); }
};
Grid.defaultRenderCell = defaultRenderCell;

return Grid;
});

0 comments on commit ce06c38

Please sign in to comment.