Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter scope #470

Merged
7 commits merged into from
Mar 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function(kernel, declare, listen, has, put, List, miscUtil){
},

renderRow: function(object, options){
var self = this;
var row = this.createRowCells("td", function(td, column){
var data = object;
// we support the field, get, and formatter properties like the DataGrid
Expand All @@ -152,8 +153,15 @@ function(kernel, declare, listen, has, put, List, miscUtil){
}else if("field" in column && column.field != "_item"){
data = data[column.field];
}
if(column.formatter){
td.innerHTML = column.formatter(data);
var formatter = column.formatter;
if(formatter){
//we support formatterScope like the DataGrid
var scope = self.formatterScope;
if(scope && typeof formatter == "string"){
formatter = scope[formatter];
}

td.innerHTML = formatter(data, object);
}else if(column.renderCell){
// A column can provide a renderCell method to do its own DOM manipulation,
// event handling, etc.
Expand Down
4 changes: 2 additions & 2 deletions List.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,12 @@ function(kernel, declare, listen, has, miscUtil, TouchScroll, hasClass, put){
// Sets named properties on a List object.
// A programmatic setter may be defined in subclasses.
//
// set() may also be called with a hash of name/value pairs, ex:
// set() may also be called with a hash of name/value pairs, ex:
// | myObj.set({
// | foo: "Howdy",
// | bar: 3
// | })
// This is equivalent to calling set(foo, "Howdy") and set(bar, 3)
// This is equivalent to calling set(foo, "Howdy") and set(bar, 3)

if(typeof name === "object"){
for(var k in name){
Expand Down
2 changes: 1 addition & 1 deletion Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ return declare(null, {
// If true, the selection object will be cleared when refresh is called.
deselectOnRefresh: true,

//allowSelectAll: Boolean
// allowSelectAll: Boolean
// If true, allow ctrl/cmd+A to select all rows.
// Also consulted by the selector plugin for showing select-all checkbox.
allowSelectAll: false,
Expand Down
4 changes: 2 additions & 2 deletions extensions/DnD.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ define([
"dojo/has!touch?./_DnD-touch-autoscroll",
"xstyle/css!dojo/resources/dnd.css"
], function(declare, lang, arrayUtil, Deferred, aspect, on, topic, has, DnDSource, DnDManager, NodeList, put, touchUtil){
// Requirements:
// Requirements
// * requires a store (sounds obvious, but not all Lists/Grids have stores...)
// * must support options.before in put calls
// (if undefined, put at end)
// * should support copy
// (copy should also support options.before as above)

// TODOs:
// TODOs
// * consider sending items rather than nodes to onDropExternal/Internal
// * consider emitting store errors via OnDemandList._trackError

Expand Down
85 changes: 85 additions & 0 deletions test/formatters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test formatters and formatterScope</title>
<meta name="viewport" content="width=570">
<style>
@import "../../dojo/resources/dojo.css";
@import "../css/dgrid.css";
@import "../css/skins/claro.css";
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
#grid {
width: 400px;
}

/* styles for autoheight */
#grid {
height: auto;
}
#grid .dgrid-scroller {
position: relative;
overflow-y: hidden;
}
.has-ie-6 #grid .dgrid-scroller {
/* IE6 doesn't react properly to hidden on this page for some reason */
overflow-y: visible;
}
#grid .dgrid-header-scroll {
display: none;
}
#grid .dgrid-header {
right: 0;
}
</style>
<script src="../../dojo/dojo.js"
data-dojo-config="async: true"></script>
<script>
require(["dgrid/OnDemandGrid","dojo/_base/declare", "dojo/date/locale", "dgrid/test/data/base", "dojo/domReady!"],
function(Grid, declare, locale){
//we can define our formatterScope object and
//then simply define formatter for column
//as a string matching name of predefined function
var formatterScope = {
date: function(value){
return locale.format(value,{
selector: "date",
formatLength: "short"
});
}
}

window.grid = new Grid({
formatterScope: formatterScope,
store: testTypesStore,
columns: {
floatNum: 'Real Number',
integer: 'Integer',
text: 'Text',
date2: {
label: 'Date',
//formatter from formatterScope object
formatter: "date"
},
bool: {
label: 'Check',
//normal formatter function
formatter: function(val){
return val ? "yes" : "no";
}
}
}
}, "grid");
});

</script>
</head>
<body class="claro">
<h2>A basic grid with height:auto</h2>
<div id="grid"></div>
<a href="https://github.com/SitePen/dgrid">dgrid</a>
</body>
</html>