TableSortHeading

From $1

    Table of contents
    No headers
    /**
     * Table Sort Heading
     * 
     * @param list $columns - list of maps/str to generate headings
     * @param uri $uri - base uri (default: page.uri)
     * @param map $params - query params to preserve
     * @param str $default - default field to sort by
     * @param bool $enabled - allow sorting (default: true)
     */
    var uri = $uri ?? page.uri;
    var params = $params ?? {};
    var columns = $columns ?? [];
    var sortEnabled = $enabled ?? true;
    var sortKey = $key ?? "sortby";
    var sortField = $current ?? __request.args[sortKey] ?? $default ?? "";
    
    // determine the current sorting information
    var sortDesc = string.startswith(sortField, "-");
    if (sortDesc) {
        let sortField = string.substr(sortField, 1);
    }
    
    // generate column widths
    <colgroup>
    foreach (var column in columns) {
        <col class=("col-" .. __count .. " " .. column.class) width=(column.width ?? "") />
    }
    </colgroup>
    
    <thead>
        <tr>
            foreach (var column in columns) {
                var headingClass = column.class;
                // auto-classing
                let headingClass ..= " sortable col-" .. __count;
                let headingClass ..= (sortEnabled ? "" : " ui-state-disabled");
                <th class=(headingClass) title=(column.label)>
                    var sortClass = column.sortclass;
                    if (sortEnabled && column.field) {
    
                        // sortable column
                        var text = column.label;
                        var columnSortField = column.field;
                        var columnSortType = string.startswith(columnSortField, "-") ? "-" : "";
                        if (columnSortType == "-") {
                            let columnSortField = substr(columnSortField, 1);
                        }
    
                        // check if we are sorting by this column
                        if (columnSortField == sortField) {
                            let columnSortType = sortDesc ? "" : "-";
                            let sortClass ..= sortDesc ? " sort-desc" : " sort-asc";
                        }
    
                        // generate the sort heading
                        var columnParams = params .. {(sortKey): (columnSortType .. columnSortField)};
                        <a class=(sortClass) href=(uri & columnParams)>text;</a>
                    } else {
                        if (!column.field) {
                            let sortClass ..= " nosort"; 
                        }
                        <span class=(sortClass)><span>column.label</span></span>;
                    }
                </th>
            }
        </tr>
    </thead>
    
    
    Tags: (Edit tags)
    • No tags
     
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch Core

    Disclaimer: Vespa Labs contains information that is VERY likely to wreck your scooter and possibly yourself both intentionally (i.e. gaining more peformance while sacrificing reliability + safety) and unintentionally (i.e. misleading or incorrect information). Vespa Labs is only a wiki and intended as a dumping ground for information and not as a properly reviewed source. The same disclaimers that wikipedia.org use apply to Vespa Labs. The short version is use information at your own risk, both information on the main wiki and in the user areas are intended to be used only as "thought provoking" for someone that knows what they are doing. If you try to implement a "thought" Vespa Labs is not reponsible and if something goes wrong we hope that you live and update the offending information with corrections to warn others.

    Vespa Labs is an international site and therefore may contain information that is not road legal in some countries/states and may also invalidate insurance policies. Treat all information as experimental and for "race use only" (i.e. not for road use - even if it is implied or explicitly stated). Refer to and adhere to your local road and legal rules, as well as the manufacturers recommendations.