baaGrid User Guide
Index |
||
| Basic methods | ||
| baaGrid | Create new datagrid object | |
| display | Echo the datagrid to the page | |
| printGrid | Echo the datagrid to the page ( alias for display() ) | |
| showErrors | Turn error reporting on | |
| Grid appearance | ||
| setTableAttr | Set table attributes | |
| setHeadings | Set grid column headings | |
| setHeaderClass | Set class name(s) for heading style(s) | |
| setColClass | Set class name(s) for column style(s) | |
| setTotalClass | Set class name(s) for total row style(s) | |
| setSubTotalClass | Set class name(s) for total row style(s) | |
| setRowClass | Set class name(s) for row style(s) | |
| setWidth | Set column width | |
| setDateFormat | Set date format | |
| setAlign | Set column alignment | |
| setDecPlaces | Set number of decimal places | |
| showColNumbers | Show column numbers in header cells (programming aid) | |
| Advanced features | ||
| setTotal | Set a column to be totalled | |
| setCount | Set row count column | |
| setOnChange | Specify a column contents displayed only when value changes | |
| setCondition | Set conditional hilighting for a cell | |
| hideColumn | Hide a selected column | |
| setLink | Set link to URL on a cell | |
| setXTab | Prepares a cross-tab (pivot table) instead of a list | |
| setGPCol | General Purpose - Parse column contents and substitute field values | |
| setSpan | Set colspan and rowspan values | |
| Code samples and tutorial | ||
| Download class | ||
| Download guide with tutorial | ||
Method Reference |
||||||||
|index| |
baaGrid object baaGrid (query [, dbtype[,dbConnection]]) | |||||||
| query | a valid SQL query | |||||||
| dbtype | [optional] the type of database you are using. Default is MySQL | |||||||
| dbConnection | [required for ODBC only] the link resource returned by odbc_connect() | |||||||
|
||||||||
|index| |
display() or printGrid() | |||||||
| No parameters | -- | |||||||
Outputs the query results in the formatted table |
||||||||
|index| |
showErrors([show]) | |||||||
| show | [optional]Boolean 1 or True to turn on error display | |||||||
showErrors() is equivalent to showErrors(True) |
||||||||
|index| |
setTableAttr(attributes) | |||||||
| attributes | string containing the table attributes | |||||||
eg setTableAttr("WIDTH=\"600\"") |
||||||||
|index| |
setHeadings(headings) | |||||||
| headings | array of column headings or a comma-delimited string | |||||||
eg setHeadings("First\nName,Last\nName,Email address") |
||||||||
|index| |
setHeaderClass(classnames) | |||||||
| classnames | array or comma-delinited list of style class names | |||||||
The class names must have been defined in your page <STYLE> section
<style>
.cl1 {background : #666666}
.cl2 {background : #C0C0C0}
</style>
The last style specified in the list is applied to the remaining columns So setHeaderClass('cl2') will apply a light-grey background to all header cells
and setHeaderClass('cl1,cl2') sets the first cell as mid-grey and the rest light-grey |
||||||||
|index| |
setColClass(classnames) | |||||||
| classnames | array or comma-delimited list of style class names | |||||||
The class usage is the same as setHeaderCells |
||||||||
|index| |
setTotalClass(classnames) | |||||||
| classnames | array or comma-delimited list of style class names | |||||||
The class usage is the same as setHeaderCells If totals are specified and no total class defined then the header classes are used for the totals |
||||||||
|index| |
setSubTotalClass(classnames) | |||||||
| classnames | array or comma-delimited list of style class names | |||||||
The class usage is the same as setHeaderCells If subtotals are specified and no subtotal class defined then the total classes are used for the subtotals, or header classes if no total class defined |
||||||||
|index| |
setRowClass(classnames) | |||||||
| classnames | array or comma-delimited list of style class names | |||||||
The class definition is the same as setHeaderCells, however, with row classes, the pattern of styles is repeated throughout the data rows, so <style>
.cl1 {background : #666666}
.cl2 {background : #C0C0C0}
</style>
with
setRowClass('cl1, cl1, cl2, cl2') gives alternating double grey bands
|
||||||||
|index| |
setWidth(column, width) | |||||||
| column | the column number to be set (first column id 0) | |||||||
| width | the column width | |||||||
setWidth(2,150)or a percentage width setWidth(2,'25%') |
||||||||
|index| |
setDateFormat(format) | |||||||
| format | date format string as used in date() function | |||||||
Default is 'd M y'. ie 01 Jan 03 |
||||||||
|index| |
setAlign(column, alignment) | |||||||
| column | column number | |||||||
| alignment | text alignment string ('L', 'C' or 'R') | |||||||
|
||||||||
|index| |
setDecPlaces(column, places [,alignment]) | |||||||
| column | column number | |||||||
| places | number of decimal places | |||||||
| alignment | [optional]text alignment | |||||||
|
||||||||
|index| |
showColNumbers([show]) | |||||||
| show | optional, default is 'true' | |||||||
|
||||||||
|index| |
setTotal(column [, places]) | |||||||
| column | column number | |||||||
| places | [optional] number of decimal places for column | |||||||
|
||||||||
|index| |
setCount(column) | |||||||
| column | column number | |||||||
Cause a record count to be output in the total row of that column. |
||||||||
|index| |
setOnChange(column [, subtotals [, blankrow]]) | |||||||
| column | column number | |||||||
| subtotals | 1 if subtotals required on change of value in specified column, 0 if not | |||||||
| blankrow | 1 if blank row required between changes of value in specified column, 0 if not 2 if you want blank row and headings repeated |
|||||||
Record count totals specified for the OnChange column will show the number of unique values in the column rather than the record count. Subtotals on the OnChange column are suppressed. |
||||||||
|index| |
setCondition(column, test, value, backgound, foreground [, legend]) | |||||||
| column | column number of cell to be hilighted if comparison is true | |||||||
| test | the comparison operator to be applied | |||||||
| value | value that the field value is to be compared with | |||||||
| background | the cell background colour to be used | |||||||
| foreground | text colour to be used | |||||||
| legend | [optional] explanatory text to appear in legend below the grid | |||||||
In addition, for text fields, you can use
'?' field contains value
'!' field does not contain value
You can define more than one condition for a column. In this case the tests are applied in the order they are specified and the test function returns as soon as a true test result is found. You have to be careful, therefore of the order in which you specify the conditions. All the above comparisons compare the value in the specified column with the 'value' parameter using the simple comparison. You can also highlight a cell in one column based on the contents of one or more of the other columns in a row using the final 'test' value '#' When you use a '#' test, the 'value' parameter should be a string containing a boolean expression. Field values in the expression are specified using #0, #1 etc where 0 and 1 are the column numbers. Functions in the expression can be a php or user functions. If a field value is a string or date, place the #0 in quotes. (As in simple comparisons above, dates are passed unformatted) The legend heading is a DEFINE at the beginning of the class code for ease of change, particularly for other languages Examples Hightlight in blue background a sales value in column 4 if the quantity in column 3 is less than 10
setCondition(4,'#',"#3 < 10", "#CCCCFF","")
Hightlight in red text a sales value in column 4 if the product code in column 1 begins with 'X' and create explanatory legend below the grid.
setCondition(4,'#',"substr('#1',0,1)=='X'", "","#FF0000","Experimental product sales")
|
||||||||
|index| |
setLink(column, url) | |||||||
| column | column number | |||||||
| url | Specifies the href parameter for the link | |||||||
setLink(2,"$_SERVER[PHP_SELF]?id=#5&action=delete")
|
||||||||
|index| |
hideColumn(column) | |||||||
| column | column number | |||||||
|
||||||||
|index| |
setXTab(row, column, aggregate [, analysis]) | |||||||
| row | the data column number whose values are to be the row headings | |||||||
| column | the data column number whose values are to be the column headings | |||||||
| aggregate | the data column number to be aggregated | |||||||
| analysis | [optional]type of analysis. Default is total. Can also be average or count
|
|||||||
|
||||||||
|index| |
setGPCol(column[,content]) | |||||||
| column | column number | |||||||
| content | optional column contents (added version 1.3a) | |||||||
$sql = "select id, name, department, '<input type=\"checkbox\" name=\"del[]\" value=\"#0\">' as Del from employee order by name"; and then setGPCol(3); Alternatively, (version 1.3a) ensure query has an extra column as a placeholder $sql = "select id, name, department, '' as Del from employee order by name"; and then setGPCol(3, '<input type="checkbox" name="del[]" value="#0">'); (version 1.7) Content can be a function call and the result of the function is output
$sql = "select id, name, department, '' as Result
from employee order by name";
eg setGPCol(3, 'myfunction(#1, #2)');
|
||||||||
|index| |
setSpan(column, startnewrow [,colspan [, rowspan ]]) | |||||||
| column | column number | |||||||
| startnewrow | 1 to start a new row, zero for same row | |||||||
| colspan | [optional] number of columns to be spanned (values of 0 or 1 are ignored) | |||||||
| rowspan | [optional] number of rows to be spanned (values of 0 or 1 are ignored) | |||||||
Headings and total rows use the same cell pattern Example : SELECT a, b, c, d, e FROM tablename
$grid->setSpan (0,0,0,2); // field a (col 0) rowspan = 2
$grid->setSpan (1,0,2); // field b (col 1) colspan = 2
$grid->setSpan(2,0,0,2); // field c (col 2) rowspan = 2
$grid->setSpan (3,1); // field d (col 3) starts second row
|
||||||||