     contains = false
 
     $.each data, (key, value) =>
-    
+
       if _.isObject(value) or _.isArray(value)
          contains = @JSONcontains value, query
          return !contains # if contains then break else continue



  retrieveData : ->
       
    ajaxOptions =
      url : @pageSelectionDiv.data("url")
      dataType : "json"
      type : "get"

    $.ajax(ajaxOptions).then(@handleData)

  handleData: (responseData) =>
    
    @allElements = @elementsToShow = responseData.data

    pageCount = Math.ceil(@allElements.length / @rowsPerPage)
    
    pageSelectionHandler = (event, number) =>
      index = number - 1
      json = @getElementsForPage(index)
      @displayJSON(json)
    
    @pageSelectionDiv.bootpag(
      total: pageCount
      page: 1

###

class Paginator


  constructor: (@pageSelectionDiv, data=null) ->

    @rowsPerPage = 100
    @allElements = null
    @elementsToShow = null

    tableID = @pageSelectionDiv.data("paged-table-id")
    @tbody = $("#"+tableID).find("tbody")

    @extractTemplate()

    if data
      @handleData(data)
    else
      @retrieveData()

    searchboxElement = @pageSelectionDiv.find(".pagination-searchbox")
    @addSearchboxListener(searchboxElement)
    @addHashListener(searchboxElement)
