     scope: true
     compile: (element, attributes, transclude) ->
       setup = createSetup attributes
-      constructHeader(element)
+
+      thead = element.find "thead"
+      tds = element.find "td"
+      constructHeader(thead, tds) if thead[0]
+
       setup.compile(element, attributes, transclude)
       {
         post: ($scope, $element, $attributes) ->

angular.module("angular-table").directive "atTable", ["attributeExtractor", (attributeExtractor) ->

  capitaliseFirstLetter = (string) ->
    string.charAt(0).toUpperCase() + string.slice(1)

  constructHeader = (element) ->
    thead = element.find "thead"

    if thead[0]
      tr = thead.find "tr"
      existing_ths = {}
      for th in tr.find "th"
        th = angular.element(th)
        existing_ths[th.attr("attribute")] = th.html()

      tr.remove()
      tr = $("<tr></tr>")

      tds = element.find("td")
      for td in tds
        td = angular.element(td)
        attribute = attributeExtractor.extractAttribute(td)
        th = $("<th style='cursor: pointer; -webkit-user-select: none;'></th>")
        title = existing_ths[attribute] || capitaliseFirstLetter(attributeExtractor.extractTitle(td))
        th.html("#{title}")

        sortable = td[0].attributes.sortable || attributeExtractor.isSortable(td.attr("class"))
        if sortable
          th.attr("ng-click", "predicate = '#{attribute}'; descending = !descending;")
          icon = angular.element("<i style='margin-left: 10px;'></i>")
          icon.attr("ng-class", "getSortIcon('#{attribute}')")
          th.append(icon)

        width = attributeExtractor.extractWidth(td.attr("class"))
        th.attr("width", width)
        tr.append(th)

      thead.append tr

  validateInput = (attributes) ->
    if attributes.pagination and attributes.list

    return

  PaginationSetup = (attributes) ->

    @repeatString = "item in #{attributes.pagination}.list #{orderByExpression} #{limitToExpression}"

    @compile = (element, attributes, transclude) ->
      tbody = setupTr element, @repeatString
