Skip to content

Instantly share code, notes, and snippets.

@pellekrogholt
Created September 23, 2013 08:30
Show Gist options
  • Save pellekrogholt/6667893 to your computer and use it in GitHub Desktop.
Save pellekrogholt/6667893 to your computer and use it in GitHub Desktop.
simple backgrid exmple as cofffe
log = (args...) ->
console.log.apply console, args if console.log?
# ------------------------------------- MODEL / COLLECTIONS
Territory = Backbone.Model.extend()
Territories = Backbone.Collection.extend(
model: Territory
url: "http://localhost:9000/territories.json"
)
# ------------------------------------- GRID
#Column definitions
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
]
# ------------------------------------- INIT APP
$ -> # document is ready!
log "ping"
territories = new Territories()
log territories
# Initialize a new Grid instance
grid = new Backgrid.Grid({
columns: columns
collection: territories
})
# // Fetch some countries from the url
territories.fetch(
success: $("body").append(grid.render().el)
failure: log "some thing went wrong"
reset: true
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment