Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ################ |
| 2 | HTML Table Class |
| 3 | ################ |
| 4 | |
| 5 | The Table Class provides functions that enable you to auto-generate HTML |
| 6 | tables from arrays or database result sets. |
| 7 | |
Andrey Andreev | cc04209 | 2014-01-03 17:08:27 +0200 | [diff] [blame] | 8 | .. contents:: |
| 9 | :local: |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 10 | |
| 11 | .. raw:: html |
| 12 | |
Andrey Andreev | cc04209 | 2014-01-03 17:08:27 +0200 | [diff] [blame] | 13 | <div class="custom-index container"></div> |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 14 | |
| 15 | ********************* |
| 16 | Using the Table Class |
| 17 | ********************* |
| 18 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 19 | Initializing the Class |
| 20 | ====================== |
| 21 | |
| 22 | Like most other classes in CodeIgniter, the Table class is initialized |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 23 | in your controller using the ``$this->load->library()`` method:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 24 | |
| 25 | $this->load->library('table'); |
| 26 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 27 | Once loaded, the Table library object will be available using:: |
| 28 | |
| 29 | $this->table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 30 | |
| 31 | Examples |
| 32 | ======== |
| 33 | |
| 34 | Here is an example showing how you can create a table from a |
| 35 | multi-dimensional array. Note that the first array index will become the |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 36 | table heading (or you can set your own headings using the ``set_heading()`` |
| 37 | method described in the function reference below). |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 38 | |
| 39 | :: |
| 40 | |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 41 | $this->load->library('table'); |
| 42 | |
| 43 | $data = array( |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 44 | array('Name', 'Color', 'Size'), |
| 45 | array('Fred', 'Blue', 'Small'), |
| 46 | array('Mary', 'Red', 'Large'), |
| 47 | array('John', 'Green', 'Medium') |
| 48 | ); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 49 | |
| 50 | echo $this->table->generate($data); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 51 | |
| 52 | Here is an example of a table created from a database query result. The |
| 53 | table class will automatically generate the headings based on the table |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 54 | names (or you can set your own headings using the ``set_heading()`` |
| 55 | method described in the class reference below). |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | |
| 57 | :: |
| 58 | |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 59 | $this->load->library('table'); |
| 60 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 61 | $query = $this->db->query('SELECT * FROM my_table'); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 62 | |
| 63 | echo $this->table->generate($query); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 64 | |
| 65 | Here is an example showing how you might create a table using discrete |
| 66 | parameters:: |
| 67 | |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 68 | $this->load->library('table'); |
| 69 | |
| 70 | $this->table->set_heading('Name', 'Color', 'Size'); |
| 71 | |
| 72 | $this->table->add_row('Fred', 'Blue', 'Small'); |
| 73 | $this->table->add_row('Mary', 'Red', 'Large'); |
| 74 | $this->table->add_row('John', 'Green', 'Medium'); |
| 75 | |
| 76 | echo $this->table->generate(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 77 | |
| 78 | Here is the same example, except instead of individual parameters, |
| 79 | arrays are used:: |
| 80 | |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 81 | $this->load->library('table'); |
| 82 | |
| 83 | $this->table->set_heading(array('Name', 'Color', 'Size')); |
| 84 | |
| 85 | $this->table->add_row(array('Fred', 'Blue', 'Small')); |
| 86 | $this->table->add_row(array('Mary', 'Red', 'Large')); |
| 87 | $this->table->add_row(array('John', 'Green', 'Medium')); |
| 88 | |
| 89 | echo $this->table->generate(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 90 | |
| 91 | Changing the Look of Your Table |
| 92 | =============================== |
| 93 | |
| 94 | The Table Class permits you to set a table template with which you can |
| 95 | specify the design of your layout. Here is the template prototype:: |
| 96 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 97 | $template = array( |
| 98 | 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 99 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 100 | 'heading_row_start' => '<tr>', |
| 101 | 'heading_row_end' => '</tr>', |
| 102 | 'heading_cell_start' => '<th>', |
| 103 | 'heading_cell_end' => '</th>', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 104 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 105 | 'row_start' => '<tr>', |
| 106 | 'row_end' => '</tr>', |
| 107 | 'cell_start' => '<td>', |
| 108 | 'cell_end' => '</td>', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 109 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 110 | 'row_alt_start' => '<tr>', |
| 111 | 'row_alt_end' => '</tr>', |
| 112 | 'cell_alt_start' => '<td>', |
| 113 | 'cell_alt_end' => '</td>', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 114 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 115 | 'table_close' => '</table>' |
| 116 | ); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 117 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 118 | $this->table->set_template($template); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 119 | |
| 120 | .. note:: You'll notice there are two sets of "row" blocks in the |
| 121 | template. These permit you to create alternating row colors or design |
| 122 | elements that alternate with each iteration of the row data. |
| 123 | |
| 124 | You are NOT required to submit a complete template. If you only need to |
| 125 | change parts of the layout you can simply submit those elements. In this |
| 126 | example, only the table opening tag is being changed:: |
| 127 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 128 | $template = array( |
| 129 | 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' |
| 130 | ); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 131 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 132 | $this->table->set_template($template); |
Mike Funk | 46e3a9a | 2012-02-24 09:38:35 -0500 | [diff] [blame] | 133 | |
| 134 | You can also set defaults for these in a config file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 135 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 136 | *************** |
| 137 | Class Reference |
| 138 | *************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 139 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 140 | .. class:: CI_Table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 141 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 142 | .. attribute:: $function = FALSE |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 143 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 144 | Allows you to specify a native PHP function or a valid function array object to be applied to all cell data. |
| 145 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 146 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 147 | $this->load->library('table'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 148 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 149 | $this->table->set_heading('Name', 'Color', 'Size'); |
| 150 | $this->table->add_row('Fred', '<strong>Blue</strong>', 'Small'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 151 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 152 | $this->table->function = 'htmlspecialchars'; |
| 153 | echo $this->table->generate(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 154 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 155 | In the above example, all cell data would be ran through PHP's :php:func:`htmlspecialchars()` function, resulting in:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 156 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 157 | <td>Fred</td><td><strong>Blue</strong></td><td>Small</td> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 158 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 159 | .. method:: generate([$table_data = NULL]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 160 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 161 | :param mixed $table_data: data to populate the table rows with |
| 162 | :returns: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 163 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 164 | Returns a string containing the generated table. Accepts an optional parameter which can be an array or a database result object. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 165 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 166 | .. method:: set_caption($caption) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 167 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 168 | :param string $caption: table caption |
| 169 | :returns: void |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 170 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 171 | Permits you to add a caption to the table. |
| 172 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 173 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 174 | $this->table->set_caption('Colors'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 175 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 176 | .. method:: set_heading([$args = array()[, ...]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 177 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 178 | :param mixed $args: an array or multiple strings containing the table column titles |
| 179 | :returns: void |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 180 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 181 | Permits you to set the table heading. You can submit an array or discrete params:: |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 182 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 183 | $this->table->set_heading('Name', 'Color', 'Size'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 184 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 185 | $this->table->set_heading(array('Name', 'Color', 'Size')); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 186 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 187 | .. method:: add_row([$args = array()[, ...]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 188 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 189 | :param mixed $args: an array or multiple strings containing the row values |
| 190 | :returns: void |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 191 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 192 | Permits you to add a row to your table. You can submit an array or discrete params:: |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 193 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 194 | $this->table->add_row('Blue', 'Red', 'Green'); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 195 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 196 | $this->table->add_row(array('Blue', 'Red', 'Green')); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 197 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 198 | If you would like to set an individual cell's tag attributes, you can use an associative array for that cell. |
| 199 | The associative key **data** defines the cell's data. Any other key => val pairs are added as key='val' attributes to the tag:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 200 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 201 | $cell = array('data' => 'Blue', 'class' => 'highlight', 'colspan' => 2); |
| 202 | $this->table->add_row($cell, 'Red', 'Green'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 203 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 204 | // generates |
| 205 | // <td class='highlight' colspan='2'>Blue</td><td>Red</td><td>Green</td> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 206 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 207 | .. method:: make_columns([$array = array()[, $col_limit = 0]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 208 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 209 | :param array $array: an array containing multiple rows' data |
| 210 | :param int $col_limit: count of columns in the table |
| 211 | :returns: array |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 212 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 213 | This method takes a one-dimensional array as input and creates a multi-dimensional array with a depth equal to the number of columns desired. |
| 214 | This allows a single array with many elements to be displayed in a table that has a fixed column count. Consider this example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 215 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 216 | $list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 217 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 218 | $new_list = $this->table->make_columns($list, 3); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 219 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 220 | $this->table->generate($new_list); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 221 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 222 | // Generates a table with this prototype |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 223 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 224 | <table border="0" cellpadding="4" cellspacing="0"> |
| 225 | <tr> |
| 226 | <td>one</td><td>two</td><td>three</td> |
| 227 | </tr><tr> |
| 228 | <td>four</td><td>five</td><td>six</td> |
| 229 | </tr><tr> |
| 230 | <td>seven</td><td>eight</td><td>nine</td> |
| 231 | </tr><tr> |
| 232 | <td>ten</td><td>eleven</td><td>twelve</td></tr> |
| 233 | </table> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 234 | |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 235 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 236 | .. method:: set_template($template) |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 237 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 238 | :param array $template: associative array containing template values |
| 239 | :returns: bool |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 240 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 241 | Permits you to set your template. You can submit a full or partial template. |
| 242 | :: |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 243 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 244 | $template = array( |
| 245 | 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' |
| 246 | ); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 247 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 248 | $this->table->set_template($template); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 249 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 250 | .. method:: set_empty($value) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 251 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 252 | :param mixed $value: value to put in empty cells |
| 253 | :returns: void |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 254 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 255 | Lets you set a default value for use in any table cells that are empty. |
| 256 | You might, for example, set a non-breaking space:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 257 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 258 | $this->table->set_empty(" "); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 259 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 260 | .. method:: clear() |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 261 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 262 | :returns: void |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 263 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 264 | Lets you clear the table heading and row data. If you need to show multiple tables with different data you should to call this method |
| 265 | after each table has been generated to clear the previous table information. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 266 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 267 | $this->load->library('table'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 268 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 269 | $this->table->set_heading('Name', 'Color', 'Size'); |
| 270 | $this->table->add_row('Fred', 'Blue', 'Small'); |
| 271 | $this->table->add_row('Mary', 'Red', 'Large'); |
| 272 | $this->table->add_row('John', 'Green', 'Medium'); |
| 273 | |
| 274 | echo $this->table->generate(); |
| 275 | |
| 276 | $this->table->clear(); |
| 277 | |
| 278 | $this->table->set_heading('Name', 'Day', 'Delivery'); |
| 279 | $this->table->add_row('Fred', 'Wednesday', 'Express'); |
| 280 | $this->table->add_row('Mary', 'Monday', 'Air'); |
| 281 | $this->table->add_row('John', 'Saturday', 'Overnight'); |
| 282 | |
Andrey Andreev | cc04209 | 2014-01-03 17:08:27 +0200 | [diff] [blame] | 283 | echo $this->table->generate(); |