I'm trying to implement BackGrid using a Backbone boilerplate from the following location: https://github.com/azat-co/super-simple-backbone-starter-kit
1.Created a file called GridHandler.js with the following code:
var Territory = Backbone.Model.extend({});
var Territories = Backbone.Collection.extend({
model: Territory,
url: "data/territories.json"
});
var territories = new Territories();
var columns = [{
name: "id", // The key of the model attribute
label: "ID", // The name to display in the header
editable: false, // By default every cell in a column is editable, but *ID* shouldn't be
// Defines a cell type, and ID is displayed as an integer without the ',' separating 1000s.
cell: Backgrid.IntegerCell.extend({
orderSeparator: ''
})
}, {
name: "name",
label: "Name",
// The cell type can be a reference of a Backgrid.Cell subclass, any Backgrid.Cell subclass instances like *id* above, or a string
cell: "string" // This is converted to "StringCell" and a corresponding class in the Backgrid package namespace is looked up
}, {
name: "pop",
label: "Population",
cell: "integer" // An integer cell is a number cell that displays humanized integers
}, {
name: "percentage",
label: "% of World Population",
cell: "number" // A cell type for floating point value, defaults to have a precision 2 decimal numbers
}, {
name: "date",
label: "Date",
cell: "date"
}, {
name: "url",
label: "URL",
cell: "uri" // Renders the value in an HTML anchor element
}];
2.grid.html file contains a DIV with id 'example-1-result'.
3.In the app.js created a View as follows:
require(['libs/text!header.html', 'libs/text!home.html', 'libs/text!grid.html', 'libs/text!footer.html', 'js/GridHandler'],
function (headerTpl, homeTpl, gridTpl, footerTpl, gridHandler) {
// Other Views here.
GridView = Backbone.View.extend({
el: "#content",
template: gridTpl,
initialize: function() {
// Initialize a new Grid instance
var grid = new Backgrid.Grid({
columns: columns,
collection: territories
});
// Render the grid and attach the root to your HTML document
$("#example-1-result").append(grid.render().el);
// Fetch some countries from the url
territories.fetch({reset: true});
},
render: function() {
$(this.el).html(_.template(this.template));
}
});
app = new ApplicationRouter();
Backbone.history.start();
});
The grid is not showing even if the grid.html with the DIV tag 'example-1-result' template content is assigned to content area.
grid.render().el -> generated the grid table properly.
Why the grid is not showing in the #content -> #example-1-result ?
'#example-1-result' is in the template file, is that is the issue?
The question in another way:
How can we assign some data to a DIV which is in a template from the View?