TableSet
public class TableSet
Field Summary | |
---|---|
mixed | A string that is appended to the class names printed in the HTML to uniquely identify this table's CSS. |
mixed | An array of class CSS class names, where the index corresponds to the column heading, used to format the div tags that wrap a table cell. |
mixed | True if click sorting is enabled and the user can click a heading to automatically sort a column. |
mixed | An array of table headings or the top row of table data. |
mixed | An array of boolean values, where the index corresponds to the column heading. |
mixed | An optional string prepended to the front of any $_REQUEST variables generated during sorting or pagifying table data that distinguishes this table's parameters from another table on the same page. |
mixed | An array of CSS class names, where the index corresponds to the data row, used to format the div tags that wrap a table cell. |
mixed | An array of rows in the order that each row will be displayed where each row is an array of data. |
mixed | An array of strings equal to the exact name of a database attribute, where the array index corresponds to the column heading. |
mixed | If not empty and enableSort is true, then this TableSet will use the array values in this variable to determine, which headings can be click sorted. |
mixed | An array of class names td tags where the array index corresponds to the column number. |
Constructor Summary | |
---|---|
TableSet(string name, string classPostfix) Creates a new TableSet. |
|
__construct(string name, string classPostfix) Creates a new TableSet. |
Method Summary | |
---|---|
void | addColumn(array cells, string insertHeading, string colHeading) Adds a column of data. |
void | addRow(array cells) Appends a row to the end of the data in this table. |
void | addRows(array rows) Appends rows to the endof the data in this table. |
array | getAliases(string sql) A static method that returns an array of all the aliases contained in the specified SQL query. |
string | getAssociativeTableTag(array values) A static method that provides a single line call for generating the HTML to display an associative array |
string | getCommaDelimitedData(boolean ignoreHeadings) Returns this table's data formatted as comma delimited data. |
string | getCommaDelimitedRow(array values) A static method that returns a row of comma delimited data. |
string | getCssTag(string className, string content) Returns the content string wrapped in div tags with the specified class name. |
string | getDelimitedData(boolean ignoreHeadings, string delim) Returns this table's data formatted as delimited data. |
string | getDelimitedRow(array values, string delim) A static method that returns a row of delimited data. |
int | Returns the number of columns of data |
int | Returns the number of rows of data, not including the heading row. |
string | getTabDeliminatedData(boolean ignoreHeadings) Returns this table's data formatted as tab delimited data. |
string | getTabDeliminatedRow(array values) A static method that returns a row of tab delimited data. |
string | getTabDelimitedData(boolean ignoreHeadings) Returns this table's data formatted as tab delimited data. |
string | getTabDelimitedRow(array values) A static method that returns a row of tab delimited data. |
string | Returns the HTML to display this TableSet's data in an HTML table structure. |
string | getTranslation(string heading) Returns a sortTranslation, if any, for the specified heading. |
string | getWrappedTableTag(int cols) Returns the HTML to display this table as a group of side by side tables to maximize the amount of data that can fit on a single screen. |
void | insertIndexes(string columnHeading, string insertHeading) Inserts a column of indexes (starting at 1). |
void | loadAssociativeArray(array values, boolean generateHeading) Loads data from an associative array. |
void | loadAssociativeArrayColumnWise(array values) Loads data from an associative array. |
void | loadQuery(string sql) Loads the data from an SQL query. |
void | loadResultSet(resource rs) Loads the data from a results set. |
void | loadRowsAndColumns(array values, int rows, int cols, array headings) Loads array data and formats it into the specified number of rows and columns. |
void | translateRows(string attrName, string pattern, string className) Uses pattern to determine whether to set a row's CSS. |
public mixed $classPostfix = null
A string that is appended to the class names printed in the HTML to uniquely identify this table's CSS.
public mixed $columnClasses = null
An array of class CSS class names, where the index corresponds to the column heading, used to format the div tags that wrap a table cell.
public mixed $enableSort = false
True if click sorting is enabled and the user can click a heading to automatically sort a column. This should only be used when loading data through the loadQuery method.
public mixed $headings = array()
An array of table headings or the top row of table data.
public mixed $hideColumns = null
An array of boolean values, where the index corresponds to the column heading. A value of true will hide the column.
public mixed $name = null
An optional string prepended to the front of any $_REQUEST variables generated during sorting or pagifying table data that distinguishes this table's parameters from another table on the same page. This value is only really needed when you have two or more tables on the same page and want them to be sortable or pagifyable.
public mixed $rowClasses = null
An array of CSS class names, where the index corresponds to the data row, used to format the div tags that wrap a table cell.
public mixed $rows = null
An array of rows in the order that each row will be displayed where each row is an array of data.
public mixed $sortTranslations = null
An array of strings equal to the exact name of a database attribute, where the array index corresponds to the column heading. This array should be populated for any column that doesn't sort properly. For example, if you SQL query contains CONCAT('',id,'') AS 'ID' then when enabling click sort by default, SQL will sort ID in an unexpected way. To resolve this simply use: sortTranslations["ID"] = "id".
public mixed $sortableHeadings = array()
If not empty and enableSort is true, then this TableSet will use the array values in this variable to determine, which headings can be click sorted. The array elements in sortableHeadings are any strings found in the headings array.
public mixed $tdClasses = array()
An array of class names td tags where the array index corresponds to the column number. This variable is needed to provide CSS customization to a column at the td tag level.
public TableSet(string name, string classPostfix)
Creates a new TableSet.
public __construct(string name, string classPostfix)
Creates a new TableSet.
public void addColumn(array cells, string insertHeading, string colHeading)
Adds a column of data.
public void addRow(array cells)
Appends a row to the end of the data in this table.
public void addRows(array rows)
Appends rows to the endof the data in this table.
public array getAliases(string sql)
A static method that returns an array of all the aliases contained in the specified SQL query.
public string getAssociativeTableTag(array values)
A static method that provides a single line call for generating the HTML to display an associative array
public string getCommaDelimitedData(boolean ignoreHeadings)
Returns this table's data formatted as comma delimited data. For example, this method can be used to create tab delimited .csv files that can be imported into MS Excel.
public string getCommaDelimitedRow(array values)
A static method that returns a row of comma delimited data.
public string getCssTag(string className, string content)
Returns the content string wrapped in div tags with the specified class name.
public string getDelimitedData(boolean ignoreHeadings, string delim)
Returns this table's data formatted as delimited data.
public string getDelimitedRow(array values, string delim)
A static method that returns a row of delimited data. Note: MS Excel's way of representing double quotes within a field is by repeating the double quotes.
public int getNumColumns()
Returns the number of columns of data
public int getNumRows()
Returns the number of rows of data, not including the heading row.
public string getTabDeliminatedData(boolean ignoreHeadings)
Returns this table's data formatted as tab delimited data. For example, this method can be used to create tab delimited .txt files that can be imported into MS Excel.
public string getTabDeliminatedRow(array values)
A static method that returns a row of tab delimited data.
public string getTabDelimitedData(boolean ignoreHeadings)
Returns this table's data formatted as tab delimited data. For example, this method can be used to create tab delimited .txt files that can be imported into MS Excel.
public string getTabDelimitedRow(array values)
A static method that returns a row of tab delimited data.
public string getTableTag()
Returns the HTML to display this TableSet's data in an HTML table structure.
public string getTranslation(string heading)
Returns a sortTranslation, if any, for the specified heading. sortTranslations isa an array of strings equal to the exact name of a database attribute, where the array index corresponds to the column heading. This array should be populated for any column that doesn't sort properly. For example, if you SQL query contains CONCAT('<a href="mypage.php?id=',id,'">',id,'</a>') AS 'ID' then when enabling click sort by default, SQL will sort ID in an unexpected way. To resolve this simply use: sortTranslations["ID"] = "id".
public string getWrappedTableTag(int cols)
Returns the HTML to display this table as a group of side by side tables to maximize the amount of data that can fit on a single screen.
public void insertIndexes(string columnHeading, string insertHeading)
Inserts a column of indexes (starting at 1).
public void loadAssociativeArray(array values, boolean generateHeading)
Loads data from an associative array. This method loads
data into a 2 by n table matrix.
This method can load data in the forms:
$GLOBALS["VALUES1"] =
array(
"x" => 0.20,
"y" => 0.10,
"z" => 0.05
);
or
$GLOBALS["VALUES2"] =
array(
"x" => array(0.20, 0.1, 0.11),
"y" => array(0.10, 0.2, 0.22),
"z" => array(0.05, 0.3, 0.33)
);
public void loadAssociativeArrayColumnWise(array values)
Loads data from an associative array. This method loads
data into a n by 2 table matrix.
This method can load data in the forms:
$GLOBALS["VALUES1"] =
array(
"x" => 0.20,
"y" => 0.10,
"z" => 0.05
);
or
$GLOBALS["VALUES2"] =
array(
"x" => array(0.20, 0.1, 0.11),
"y" => array(0.10, 0.2, 0.22),
"z" => array(0.05, 0.3, 0.33)
);
public void loadQuery(string sql)
Loads the data from an SQL query. This method intelligently modifies the SQL according to any click sorting that has occured.
public void loadResultSet(resource rs)
Loads the data from a results set.
public void loadRowsAndColumns(array values, int rows, int cols, array headings)
Loads array data and formats it into the specified number of rows and columns. This method loads values in row major order.
public void translateRows(string attrName, string pattern, string className)
Uses pattern to determine whether to set a row's CSS. This method iterates through the list of rows and if the row element at index attrName is exactly equal to pattern then sets the rowClass to className for this row.
Stores table data, and displays table data formatted by CSS stylesheets. This class allows one to autogenerate HTML tables with just raw data or an SQL query.