I think that what you need is just to change the CSS styles used for the table, as Clive suggested. That would not change the output produced from theme('table')
, but it would change how that output is rendered.
If you really want to change the output, because you want to add HTML tags to what normally output for the tables, you need to override the theme function. If THEMENAME is your theme's name, then you need to write the THEMENAME_table()
function in the template.php file for your theme. you can look at the code of theme_table() as example of which code to write. Normally you want to add output, or slightly change the output, and in that case you use most of the code already used in theme_table()
.
In Drupal 7 there is another alternative, which is possible if what you want to do is alter the value of the variables passed to the theme function: Each theme function, even the ones not using a template, have a preprocess function. In this case, the variables used from the theme function are the following ones:
$variables['header']
$variables['rows']
$variables['attributes']
$variables['caption']
$variables['colgroups']
$variables['sticky']
$variables['empty']
Writing code in a function called THEMENAME_preprocess_table()
(with $variables
as parameter), you can alter the value of those variables before they are passed to the theme function.
How can I change template for tables?
For the table theme function, there aren't template files involved; it is possible to use a template file in this case too, but you should write more code to gain few. I can report how to do this, but I would not suggest doing it.
How do I use that theme for my tables?
You just call the theme function with theme('table', $variables)
, where $variables
is an array containing the values required from the theme function, which are:
- header: An array containing the table headers. Each element of the array can be either a localized string or an associative array with the following keys:
- "data": The localized title of the table column.
- "field": The database field represented in the table column (required if user is to be able to sort on this column).
- "sort": A default sort order for this column ("asc" or "desc").
- Any HTML attributes, such as "colspan", to apply to the column header cell.
- rows: An array of table rows. Every row is an array of cells, or an associative array with the following keys:
- "data": an array of cells
- Any HTML attributes, such as "class", to apply to the table row.
- "no_striping": a boolean indicating that the row should receive no 'even / odd' styling. Defaults to FALSE.
- Each cell can be either a string or an associative array with the following keys:
- "data": The string to display in the table cell.
- "header": Indicates this cell is a header.
- Any HTML attributes, such as "colspan", to apply to the table cell.