             status:
                 type: "option"
                 options: ["all", "valid", "invalid"]
-
 ###
 class Backbone.TableView extends Backbone.View
     tagName: "div"
     titleTemplate: _.template "<h2><%= model %></h2>"
     searchTemplate: _.template """
-        <input type="text" class="search-query pull-right" placeholder="<%= model.detail || model %>"></input>
+        <input type="text" class="search-query pull-right" placeholder="<%= model.detail || model %>" value="<%= data[model.query || "q"] || "" %>"></input>
     """
     paginationTemplate: _.template """
         <ul class="pager">
             <li class="pager-prev">
                 <a href="javascript:void(0)">&larr; Prev</a>
             </li>
-            <span class="badge badge-info page">1</span>
+            <span class="badge badge-info page"><%= data.page %></span>
             <li class="pager-next">
                 <a href="javascript:void(0)">Next &rarr;</a>
             </li>

        for key, val of @options
            if key != "el" and key != "collection"
                this[key] = val or this[key]
        @data = $.extend({}, @initialData, @parseQuery Backbone.history.fragment)
        @data.page = @page or 1
        @data.size = @size or 10
        return @

    # Navigate to url with new parameters in querystring
    updateUrl: (key, val) =>
        @router.navigate(@updateQueryString Backbone.history.fragment, key, val)

    # Return updated uri's querystring with key and value
    updateQueryString: (uri, key, val) ->
        re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i")
        if uri.match(re)
            # TODO delete parameter if value is empty (taking care of the &/? thing)
            return uri.replace(re, "$1" + key + "=" + val + "$2")
        else
            separator = if uri.indexOf("?") != -1 then "&" else "?"
            return uri + separator + key + "=" + val

    # Return a parsed querystring with the "?" (eg. query = "/users?hi=1&bye=hello")
    # returns {hi: "1", bye: "hello"}
    parseQuery: (uri) ->
        ret = {}
        if (i = uri.indexOf("?")) >= 0
            uri    = uri.substring(i + 1)

    # Go to the previous page in the collection
    prevPage: =>
        if @data.page > 1
            $(".page", @$el).html @data.page - 1
            @setData "page", @data.page - 1

    # Go to the next page in the collection
    nextPage: =>
        # Since we don't have a collection count, for now we use the size of
        # the last GET as an heuristic to limit the use of nextPage
        if @collection.length == @data.size
            $(".page", @$el).html @data.page + 1
            @setData "page", @data.page + 1

    # Toggle/Select sort column and direction, and update table accodingly
    toggleSort: (e) =>
        el = e.currentTarget
        cl = el.className
        sort_dir = ""
        if cl.indexOf("sorting_desc") >= 0
            sort_dir = "asc"
            cl = "sorting_asc"
        else if cl.indexOf("sorting") >= 0 or cl.indexOf("sorting_asc") >= 0
            sort_dir = "desc"
            cl = "sorting_desc"
        else
            return @
        $("th", @$el).removeClass "sorting_desc sorting_asc"
        $(el, @$el).addClass cl
        @setData "sort_col", el.abbr, "sort_dir", sort_dir

    # Apply a template to a model and return the result (string), or empty
    # string if model is false/undefined
    applyTemplate: (template, model) ->
        (model and template data: @data, model: model) or ""

    # Render skeleton of the table, creating filters and other additions,
    # and trigger an update of the collection
