Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

render_table()

Description

Render a table based on ResourceSpace data to include sorting by various columns


Required elements:-

"class" Optional class to add to table div
"headers" - Column headings using the identifier as the index,
- name - Title to display
- Sortable - can column be sorted?
- width - Optional column width

"orderbyname" - name of variable used on page to determine orderby (used to differentiate from standard search values)
"orderby" - Current order by value
"sortbyname" - name of variable used on page to determine sort
"sort" - Current sort
"defaulturl" - Default URL to construct links
"modal" - Open links in modal? (false by default)
"params" - Current parameters to use in URL
"pager" - Pager settings
- current page
- total pages
"data" - Array of data to display in table, using header identifers as indexes
- If "rowid" is specified this will be used as the id attribute for the <tr> element
- The "alerticon" can be used to specify a CSS class to use for a row status icon
- An additional 'tools' element can be included to add custom action icons
- "icon" - FontAwesome class to use for icon
- "text" - title attribute
- "url" - URl to link to
- "url:class" - The styling classes for the URL. Type: string. This tool property is optional.
- "modal" - (boolean) Open link in modal?
- "onclick" - OnClick action to add to icon

e.g.

array(
"icon"=>"fa fa-trash",
"text"=>$lang["action-delete"],
"url"=>"",
"modal"=>false,
"onclick"=>"delete_job(" . $jobs[$n]["ref"] . ");return false;"
);

array(
"icon"=>"fa fa-info",
"text"=>$lang["job_details"],
"url"=>generateURL($baseurl . "/pages/job_details.php",array("job" => $jobs[$n]["ref"])),
"modal"=>true,
);

Parameters

ColumnTypeDefaultDescription
$tabledata array - This must be constructed as detailed below

Return

void

Location

include/render_functions.php lines 5363 to 5516

Definition

 
function render_table($tabledata)
    {
    global 
$list_display_array$lang$default_perpage_list;
    
$modal = isset($tabledata["modal"]) && $tabledata["modal"];
    
$alertcolumn count(array_column($tabledata["data"],'alerticon')) > 0;
    if(isset(
$tabledata["pager"]))
        {          
        
$pageroptions = array(
            
"curpage" => $tabledata["pager"]["current"],
            
"totalpages" => $tabledata["pager"]["total"],
            
"per_page" => isset($tabledata["pager"]["per_page"]) ? $tabledata["pager"]["per_page"] : $default_perpage_list,
            
"break" => isset($tabledata["pager"]["break"]) ? $tabledata["pager"]["break"] : true,
            
"scrolltotop" => isset($tabledata["pager"]["scrolltotop"]) ? $tabledata["pager"]["scrolltotop"] : true,
            
"url" => $tabledata["defaulturl"],
            
"url_params" => $tabledata["params"],
            );
        echo 
'<div class="TopInpageNav TableNav">';
        echo 
'<div class="InpageNavLeftBlock">' escape($lang["resultsdisplay"]) . ': ';
        
// Show per page options
        
$list_display_array["all"] = 99999;
        
$pplinks = array();
        foreach(
$list_display_array as $ldopt => $ldnum)
            {
            
$lpp_name = isset($lang[$ldopt]) ? $lang[$ldopt] : $ldnum;
            if (
$pageroptions["per_page"] == $ldnum)
                {
                
$pplinks[] =  "<span class='Selected'>" escape($lpp_name) . "</span>";
                }
            else
                {
                if(isset(
$tabledata["params"]["search_go"]))
                    {
                    
$tabledata["params"]["search_go"] = "";
                    }
                
$perpageurl generateURL($pageroptions["url"],$tabledata["params"], array("per_page"=>$ldnum));
                
$pplinks[] = "<a onclick='return " . ($modal "Modal" "CentralSpace") . "Load(this, true);' href='" 
                
$perpageurl "'>" $lpp_name "</a>";
                }
            }
        echo 
implode("&nbsp;|&nbsp;"$pplinks);
        echo 
"</div> <!-- End of InpageNavLeftBlock per page div -->";
        echo 
"<div class='TablePagerHolder'>";
        
pager(falsetrue,$pageroptions);
        echo 
"</div>";
        }
    echo 
'</div>';
    echo 
"<div class='Listview " . (isset($tabledata["class"]) ? escape($tabledata["class"]) : "") . "'>\n";
    echo 
"<table border='0' cellspacing='0' cellpadding='0' class='ListviewStyle'>\n";
    echo 
"<tbody><tr class='ListviewTitleStyle'>\n";
    if(
$alertcolumn)
        {
        echo 
"<th id='RowAlertStatus' style='width: 10px;'></th>";
        }
    foreach(
$tabledata["headers"] as $header=>$headerdetails)
        {
        echo 
"<th " . ($headerdetails["name"]==$lang["tools"] ? "class='ListTools'" "") . (isset($headerdetails["width"]) ? ("style='width:" escape($headerdetails["width"]) . "'") : "") . ">";
        if(
$headerdetails["sortable"])
            {
            
$revsort = ($tabledata["sort"]=="ASC") ? "DESC" "ASC";
            echo 
"<a href='" generateURL($tabledata["defaulturl"],$tabledata["params"],array($tabledata["orderbyname"]=>$header,$tabledata["sortname"]=>($tabledata["orderby"] == $header $revsort $tabledata["sort"]))) . "' onclick='return " . ($modal "Modal" "CentralSpace") . "Load(this, true);'>" escape($headerdetails["name"]);
            if(
$tabledata["orderby"] == $header)
                {
                
// Currently sorted by this column
                
echo "<span class='" $revsort "'></span>";
                }
            echo 
"</a>";
            }
        else
            {
            echo 
escape($headerdetails["name"]);
            }
        
        
        echo 
"</th>";
        }
    echo 
"</tr>\n"// End of table header row

    
if(count($tabledata["data"]) == 0)
        {
        echo 
"<tr><td colspan='" . (strval(count($tabledata["headers"]))) . "'>" escape($lang["no_results_found"]) . "</td></tr>\n";
        }
    else
        {
        foreach(
$tabledata["data"] as $rowdata)
            {
            
$rowid = isset($rowdata["rowid"]) ? " id='" escape($rowdata["rowid"])  . "'" "";
            if(isset(
$rowdata["rowlink"]))
                {
                
$rowid .=  " class='row_clickable' data-link='" escape($rowdata["rowlink"]) . "'";
                }
            echo 
"<tr" $rowid ">";

            if(isset(
$rowdata['alerticon']))
                {
                echo 
"<td><i class='" escape($rowdata['alerticon']) . "' title = '" escape($rowdata['alerticontitle'] ?? "") . "'></i></td>";
                }
            elseif(
$alertcolumn)
                {
                echo 
"<td></td>";
                }
            foreach(
$tabledata["headers"] as $header=>$headerdetails)
                {
                if(isset(
$rowdata[$header]))
                    {
                    echo 
"<td>";
                    
// Data is present
                    
if($header == "tools")
                        {
                        echo 
"<div class='ListTools'>";
                        foreach(
$rowdata["tools"] as $toolitem)
                            {
                            echo 
"<a aria-hidden='true' href='" escape($toolitem["url"]) . "' class=\"" escape($toolitem['url:class'] ?? '') . "\" onclick='";
                            if(isset(
$toolitem["onclick"]))
                                {
                                echo 
escape($toolitem["onclick"]);
                                }
                            else
                                {
                                echo 
"return " . ($toolitem["modal"] ? "Modal" "return CentralSpace") . "Load(this,true);";
                                }
                            echo 
"' title='" escape($toolitem["text"]) . "'><i class='" escape($toolitem["icon"]) . "'></i>&nbsp;" escape($toolitem["text"]) . "</a>";
                            }
                        echo 
"</div>";
                        }
                    else
                        {
                        echo (isset(
$headerdetails["html"]) && (bool)$headerdetails["html"]) 
                                ? 
strip_tags_and_attributes($rowdata[$header], array("a","input"), array("href""target""type""class""onclick"'name''value''title')) 
                                : 
escape($rowdata[$header]);
                        }
                    echo 
"</td>";
                    }
                else
                    {
                    echo 
"<td></td>\n";
                    }
                }
            echo 
"</tr>\n";
            }
        }
    echo 
'</tbody>
    </table>
    </div>
    
    <script>
    jQuery(document).ready(function()
        {
        jQuery(".row_clickable").click(function (e, row, $element)
            {
            return ModalLoad(jQuery(this).data(\'link\'), true);
            });
        });
    </script>'
;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 13th November 2024 14:05 Europe/London time.