Skip to content

Instantly share code, notes, and snippets.

@joeyramone76
Last active December 18, 2015 05:59
Show Gist options
  • Save joeyramone76/5736346 to your computer and use it in GitHub Desktop.
Save joeyramone76/5736346 to your computer and use it in GitHub Desktop.
var Datagrid = Backbone.View.extend({
- initialize: function() {
+ initialize: function(options) {
+ this.options = options;
this.columns = this.options.columns;
this.options = _.defaults(this.options, {
paginated: false,
page: 1,
perPage: 10,
@@ -292,11 +293,12 @@ var Datagrid = Backbone.View.extend({
});
var Header = Datagrid.Header = Backbone.View.extend({
tagName: 'thead',
- initialize: function() {
+ initialize: function(options) {
+ this.options = options;
this.columns = this.options.columns;
this.sorter = this.options.sorter;
},
render: function() {
@@ -322,11 +324,12 @@ var Header = Datagrid.Header = Backbone.View.extend({
});
var Row = Datagrid.Row = Backbone.View.extend({
tagName: 'tr',
- initialize: function() {
+ initialize: function(options) {
+ this.options = options;
this.columns = this.options.columns;
this.model.on('change', this.render, this);
},
render: function() {
@@ -396,11 +399,11 @@ var Pagination = Datagrid.Pagination = Backbone.View.extend({
},
render: function() {
var $ul = $('<ul></ul>'), $li;
- $li = $('<li class="prev"><a href="#">«</a></li>');
+ $li = $('<li class="prev"><a href="#">«</a></li>');
if (!this.pager.hasPrev()) {
$li.addClass('disabled');
}
$ul.append($li);
@@ -413,11 +416,11 @@ var Pagination = Datagrid.Pagination = Backbone.View.extend({
$li.append('<a href="#">' + i + '</a>');
$ul.append($li);
}
}
- $li = $('<li class="next"><a href="#">»</a></li>');
+ $li = $('<li class="next"><a href="#">»</a></li>');
if (!this.pager.hasNext()) {
$li.addClass('disabled');
}
$ul.append($li);
@@ -440,11 +443,12 @@ var Pagination = Datagrid.Pagination = Backbone.View.extend({
});
var Cell = Datagrid.Cell = Backbone.View.extend({
tagName: 'td',
- initialize: function() {
+ initialize: function(options) {
+ this.options = this.options || options;
this.column = this.options.column;
},
render: function() {
this._prepareValue();
@@ -456,11 +460,12 @@ var Cell = Datagrid.Cell = Backbone.View.extend({
this.value = this.model.get(this.column.property);
}
});
var CallbackCell = Datagrid.CallbackCell = Cell.extend({
- initialize: function() {
+ initialize: function(options) {
+ this.options = options;
CallbackCell.__super__.initialize.call(this);
this.callback = this.options.callback;
},
_prepareValue: function() {
@@ -494,12 +499,13 @@ var ActionCell = Datagrid.ActionCell = Cell.extend({
this.value = a;
}
});
var HeaderCell = Datagrid.HeaderCell = Cell.extend({
- initialize: function() {
- HeaderCell.__super__.initialize.call(this);
+ initialize: function(options) {
+
+ HeaderCell.__super__.initialize.call(this, options);
this.sorter = this.options.sorter;
if (this.column.sortable) {
this.delegateEvents({click: 'sort'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment