Skip to content

Instantly share code, notes, and snippets.

@songjiayang
Created January 28, 2014 04:09
Show Gist options
  • Save songjiayang/8662113 to your computer and use it in GitHub Desktop.
Save songjiayang/8662113 to your computer and use it in GitHub Desktop.
this textarea cell supports text area with line breaks ..
jQuery ($)->
_.extend Backgrid.Command.prototype, {
save: () ->
!@shiftKey && @keyCode is 13
moveUp: () ->
@shiftKey && @keyCode is 38
moveDown: ()->
@shiftKey && @keyCode is 40
}
class Backgrid.TextareaFormatter extends Backgrid.StringFormatter
fromRaw: (rawValue, model)->
rawValue = rawValue.replace /</g, "&lt;"
rawValue = rawValue.replace />/g, "&gt;"
rawValue.replace /\n/g, '<br />'
class Backgrid.TextareaEditor extends Backgrid.InputCellEditor
tagName: 'textarea'
render: ()->
@$el.val @model.get(@column.get("name"), @model)
class Backgrid.TextCell extends Backgrid.StringCell
className: "text-cell"
editor: Backgrid.TextareaEditor
formatter: Backgrid.TextareaFormatter
render: ()->
@$el.empty()
@$el.html(@formatter.fromRaw(@model.get(@column.get("name")), @model))
@delegateEvents()
@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment