Collections functions
General functions
Render functions
Theme permission functions
Resource 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
- "class" - FontAwesome class to use for icon
- "text" - title attribute
- "url" - URl to link to
- "modal" - (boolean) Open link in modal?
- "onclick" - OnClick action to add to icon

e.g.

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

array(
"class"=>"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 5154 to 5303

Definition

 
function render_table($tabledata)
    {
    global 
$list_display_array$lang;
    
$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">' $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'>" htmlspecialchars($lpp_name) . "</span>";
                }
            else
                {
                
$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"]) ? htmlspecialchars($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:" htmlspecialchars($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);'>" htmlspecialchars($headerdetails["name"]);
            if(
$tabledata["orderby"] == $header)
                {
                
// Currently sorted by this column
                
echo "<span class='" $revsort "'></span>";
                }
            echo 
"</a>";
            }
        else
            {
            echo 
htmlspecialchars($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"]))) . "'>No results found<td></tr>\n";
        }
    else
        {
        foreach(
$tabledata["data"] as $rowdata)
            {
            
$rowid = isset($rowdata["rowid"]) ? " id='" htmlspecialchars($rowdata["rowid"])  . "'" "";
            if(isset(
$rowdata["rowlink"]))
                {
                
$rowid .=  " class='row_clickable' data-link='" htmlspecialchars($rowdata["rowlink"]) . "'";
                }
            echo 
"<tr" $rowid ">";

            if(isset(
$rowdata['alerticon']))
                {
                echo 
"<td><i class='" htmlspecialchars($rowdata['alerticon']) . "'></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='" htmlspecialchars($toolitem["url"]) . "' onclick='";
                            if(isset(
$toolitem["onclick"]))
                                {
                                echo 
htmlspecialchars($toolitem["onclick"]);
                                }
                            else
                                {
                                echo 
"return " . ($toolitem["modal"] ? "Modal" "return CentralSpace") . "Load(this,true);";
                                }
                            echo 
"' title='" htmlspecialchars($toolitem["text"]) . "'><span class='" htmlspecialchars($toolitem["icon"]) . "'></span></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")) 
                                : 
htmlspecialchars($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 25th May 2022 20:35 Europe/London time based on the source file dated 16th May 2022 16:30 Europe/London time.