   return @getData().columns or false
 
 # #### `table_template` String ( optional )
-#   The name of table layout template that you want to render.
-#   default is `default_table_template` found [here](lib/datatables.html)
-#   You can set your default template by assigning the template name to `Template.datatable.defaultTemplate`
+# The name of table layout template that you want to render.
+# Default is `default_table_template` found [here](lib/datatables.html).
+# You can set your default template by assigning the template name to `Template.datatable.defaultTemplate`.
 
 # ##### Default Table Template
-#   The default table template is defined in datatables.html
+# The default table template is defined in datatables.html.
 Template.dataTable.defaultTemplate = 'default_table_template'
 
 # ##### chooseTemplate Helper
-#   Return the template specified in the component parameters
-#   Set table template to default if no template name is passed in
-#   If the template is defined return it
-#   Otherwise return the default template
+# Return the template specified in the component parameters
 Template.dataTable.chooseTemplate = ( table_template = null ) ->
+  # Set table template to default if no template name is passed in
   table_template ?= Template.dataTable.defaultTemplate
+  # If the template is defined return it
   if Template[ table_template ]
     return Template[ table_template ]
+  # Otherwise return the default template
   else return Template[ @defaultTemplate ]
 
 
 # #### `collection` Meteor Collection ( required )
-#   This is the collection that house the documents your datatable is displaying
-#   This collection must be defined on both the client and the server
+# This is the collection that houses the documents your datatable is displaying
+# and must be defined on both the client and the server.
 Template.dataTable.setCollection = ( collection ) ->
   Match.test collection, Object
   @setData 'collection', collection

# ## Querying MongoDB

# ##### mapTableState()
#   Take the `aoData` parameter of `fnServerData` and map it into a more usable object
#   Convert aoData to key -> value pairs
Template.dataTable.mapTableState = ( aoData ) ->
  aoData = @arrayToDictionary aoData, 'name'
  @log 'mapTableState:aoData', aoData

  # ##### tableState
  #   `aoData.sEcho` is a request counter, incremented on every server call
  #   `aoData.columns` contains the property meta data for each column
  #   `aoData.iColumns` is the number of columns being displayed
  #   `aoData.iSortingCols` is the number of columns being sorted
  #   `aoData.iDisplayLength` is the number of rows being displayed
  #   `aoData.iDisplayStart` is the number of rows to skip for pagination
  #   `aoData.sSearch` is the datatables search input value
  tableState =
    sEcho: aoData.sEcho.value or 1
    bRegex: aoData.bRegex.value or false
    columns: []
    iColumns: aoData.iColumns.value or 0
    iSortingCols: aoData.iSortingCols.value or 0
    sColumns: aoData.sColumns.value or ""
    iDisplayLength: aoData.iDisplayLength.value or 10
    iDisplayStart: aoData.iDisplayStart.value or 0
    sSearch: aoData.sSearch.value or ""

  # ##### getDataProp()
  #   function scope helper for getting `aoData` properties
  getDataProp = ( key, index ) ->
    key = "#{ key }_#{ index }"
    return aoData[ key ].value

  # ##### mapColumns()
  #   iterator for setting up columns
  #   create an element for each column
  #   `mDataProp` is the field name
  #   `bRegex` is a boolean for if the field has a search input
  #   `bSearchable` is a boolean used to determine which fields are searchable
  #   `bSortable` is a boolean used to determine which fields are sortable
  #   `sSearch` contains the column search string if column filters are setup
  mapColumns = ( index ) ->
    tableState.columns[ getDataProp 'mDataProp', index ] =
      mDataProp: getDataProp 'mDataProp', index
      bRegex: getDataProp 'bRegex', index
      bSearchable: getDataProp 'bSearchable', index
      bSortable: getDataProp 'bSortable', index
      sSearch: getDataProp 'sSearch', index
  mapColumns index for index in [ 0..( tableState.iColumns - 1 ) ]

  # ##### mapQuery()
  #   If there is a global filter the filter query is merged with the tables default query
  #   `mapQuery()` is actually just an iterator
  #   The filter query is initialized as an `$or` of all the searchable columns against the search regex
  #   Letter case is ignored for all search querys.
  #   The `$or`'s run in parrallel in MongoDB, improving search performance
  #   You MUST still index all searchable fields
  #   If the base query is for all records in the collection, the filter query is the only query run
  #   If the base query is already filter the collection, the filter query is run as an `$and` against it
  #   e.g. all documents must pass both the table query and search query
  if tableState.sSearch isnt ""
    searchQuery = $or: []
    mapQuery = ( key, property ) ->
      unless property.bSearchable is false
        obj = {}
        obj[ key ] =
          $regex: tableState.sSearch
          $options: 'i'
        searchQuery.$or.push obj
    for key, property of tableState.columns
      mapQuery key, property
    if @getQuery is {}
      tableState.query = searchQuery
    else
      tableState.query =
        $and: [

  return index

# #### `columns` Array of Objects ( required )
# The column definitions you are passing to the datatable component. This is where to map object properties to columns
# and their headers. You can also define custom templates for rendering data in cells using the `mData` property.

# ##### setColumns()
Template.dataTable.setColumns = ( columns ) ->
