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( |
AdwinTrave | 7428ff0 | 2014-06-04 17:44:17 -0500 | [diff] [blame] | 98 | 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 99 | |
AdwinTrave | 7428ff0 | 2014-06-04 17:44:17 -0500 | [diff] [blame] | 100 | 'thead_open' => '<thead>', |
| 101 | 'thead_close' => '</thead>', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 102 | |
AdwinTrave | 7428ff0 | 2014-06-04 17:44:17 -0500 | [diff] [blame] | 103 | 'heading_row_start' => '<tr>', |
| 104 | 'heading_row_end' => '</tr>', |
| 105 | 'heading_cell_start' => '<th>', |
| 106 | 'heading_cell_end' => '</th>', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 107 | |
AdwinTrave | 7428ff0 | 2014-06-04 17:44:17 -0500 | [diff] [blame] | 108 | 'tbody_open' => '<tbody>', |
| 109 | 'tbody_close' => '</tbody>', |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 110 | |
AdwinTrave | 7428ff0 | 2014-06-04 17:44:17 -0500 | [diff] [blame] | 111 | 'row_start' => '<tr>', |
| 112 | 'row_end' => '</tr>', |
| 113 | 'cell_start' => '<td>', |
| 114 | 'cell_end' => '</td>', |
| 115 | |
| 116 | 'row_alt_start' => '<tr>', |
| 117 | 'row_alt_end' => '</tr>', |
| 118 | 'cell_alt_start' => '<td>', |
| 119 | 'cell_alt_end' => '</td>', |
| 120 | |
| 121 | 'table_close' => '</table>' |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 122 | ); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 123 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 124 | $this->table->set_template($template); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 125 | |
| 126 | .. note:: You'll notice there are two sets of "row" blocks in the |
| 127 | template. These permit you to create alternating row colors or design |
| 128 | elements that alternate with each iteration of the row data. |
| 129 | |
| 130 | You are NOT required to submit a complete template. If you only need to |
| 131 | change parts of the layout you can simply submit those elements. In this |
| 132 | example, only the table opening tag is being changed:: |
| 133 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 134 | $template = array( |
| 135 | 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' |
| 136 | ); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 137 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 138 | $this->table->set_template($template); |
Mike Funk | 46e3a9a | 2012-02-24 09:38:35 -0500 | [diff] [blame] | 139 | |
| 140 | You can also set defaults for these in a config file. |
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 | *************** |
| 143 | Class Reference |
| 144 | *************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 145 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 146 | .. php:class:: CI_Table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 147 | |
Andrey Andreev | a49c8ad | 2014-02-11 17:15:07 +0200 | [diff] [blame] | 148 | .. attribute:: $function = NULL |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 149 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 150 | Allows you to specify a native PHP function or a valid function array object to be applied to all cell data. |
| 151 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 152 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 153 | $this->load->library('table'); |
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 | $this->table->set_heading('Name', 'Color', 'Size'); |
| 156 | $this->table->add_row('Fred', '<strong>Blue</strong>', 'Small'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 157 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 158 | $this->table->function = 'htmlspecialchars'; |
| 159 | echo $this->table->generate(); |
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 | 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] | 162 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 163 | <td>Fred</td><td><strong>Blue</strong></td><td>Small</td> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 164 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 165 | .. php:method:: generate([$table_data = NULL]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 166 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 167 | :param mixed $table_data: Data to populate the table rows with |
| 168 | :returns: HTML table |
| 169 | :rtype: string |
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 | 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] | 172 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 173 | .. php:method:: set_caption($caption) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 174 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 175 | :param string $caption: Table caption |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 176 | :returns: CI_Table instance (method chaining) |
| 177 | :rtype: CI_Table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 178 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 179 | Permits you to add a caption to the table. |
| 180 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 181 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 182 | $this->table->set_caption('Colors'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 183 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 184 | .. php:method:: set_heading([$args = array()[, ...]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 185 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 186 | :param mixed $args: An array or multiple strings containing the table column titles |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 187 | :returns: CI_Table instance (method chaining) |
| 188 | :rtype: CI_Table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 189 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 190 | 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] | 191 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 192 | $this->table->set_heading('Name', 'Color', 'Size'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 193 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 194 | $this->table->set_heading(array('Name', 'Color', 'Size')); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 195 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 196 | .. php:method:: add_row([$args = array()[, ...]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 197 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 198 | :param mixed $args: An array or multiple strings containing the row values |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 199 | :returns: CI_Table instance (method chaining) |
| 200 | :rtype: CI_Table |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 201 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 202 | 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] | 203 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 204 | $this->table->add_row('Blue', 'Red', 'Green'); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 205 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 206 | $this->table->add_row(array('Blue', 'Red', 'Green')); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 207 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 208 | If you would like to set an individual cell's tag attributes, you can use an associative array for that cell. |
| 209 | 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] | 210 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 211 | $cell = array('data' => 'Blue', 'class' => 'highlight', 'colspan' => 2); |
| 212 | $this->table->add_row($cell, 'Red', 'Green'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 213 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 214 | // generates |
| 215 | // <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] | 216 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 217 | .. php:method:: make_columns([$array = array()[, $col_limit = 0]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 218 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 219 | :param array $array: An array containing multiple rows' data |
| 220 | :param int $col_limit: Count of columns in the table |
| 221 | :returns: An array of HTML table columns |
| 222 | :rtype: array |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 223 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 224 | 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. |
| 225 | 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] | 226 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 227 | $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] | 228 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 229 | $new_list = $this->table->make_columns($list, 3); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 230 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 231 | $this->table->generate($new_list); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 232 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 233 | // Generates a table with this prototype |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 234 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 235 | <table border="0" cellpadding="4" cellspacing="0"> |
| 236 | <tr> |
| 237 | <td>one</td><td>two</td><td>three</td> |
| 238 | </tr><tr> |
| 239 | <td>four</td><td>five</td><td>six</td> |
| 240 | </tr><tr> |
| 241 | <td>seven</td><td>eight</td><td>nine</td> |
| 242 | </tr><tr> |
| 243 | <td>ten</td><td>eleven</td><td>twelve</td></tr> |
| 244 | </table> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 245 | |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 246 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 247 | .. php:method:: set_template($template) |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 248 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 249 | :param array $template: An associative array containing template values |
| 250 | :returns: TRUE on success, FALSE on failure |
| 251 | :rtype: bool |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 252 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 253 | Permits you to set your template. You can submit a full or partial template. |
| 254 | :: |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 255 | |
Connor Tumbleson | 75b3fb2 | 2014-01-11 06:58:43 -0600 | [diff] [blame] | 256 | $template = array( |
| 257 | 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' |
| 258 | ); |
| 259 | |
| 260 | $this->table->set_template($template); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 261 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 262 | .. php:method:: set_empty($value) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 263 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 264 | :param mixed $value: Value to put in empty cells |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 265 | :returns: CI_Table instance (method chaining) |
| 266 | :rtype: CI_Table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 267 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 268 | Lets you set a default value for use in any table cells that are empty. |
| 269 | You might, for example, set a non-breaking space:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 270 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 271 | $this->table->set_empty(" "); |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 272 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 273 | .. php:method:: clear() |
Derek Jones | d467862 | 2011-10-05 15:40:24 -0500 | [diff] [blame] | 274 | |
Andrey Andreev | 1f59095 | 2014-02-08 19:50:26 +0200 | [diff] [blame] | 275 | :returns: CI_Table instance (method chaining) |
| 276 | :rtype: CI_Table |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 277 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 278 | 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 |
| 279 | 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] | 280 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 281 | $this->load->library('table'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 282 | |
Andrey Andreev | 0ee2a63 | 2013-09-23 18:55:38 +0300 | [diff] [blame] | 283 | $this->table->set_heading('Name', 'Color', 'Size'); |
| 284 | $this->table->add_row('Fred', 'Blue', 'Small'); |
| 285 | $this->table->add_row('Mary', 'Red', 'Large'); |
| 286 | $this->table->add_row('John', 'Green', 'Medium'); |
| 287 | |
| 288 | echo $this->table->generate(); |
| 289 | |
| 290 | $this->table->clear(); |
| 291 | |
| 292 | $this->table->set_heading('Name', 'Day', 'Delivery'); |
| 293 | $this->table->add_row('Fred', 'Wednesday', 'Express'); |
| 294 | $this->table->add_row('Mary', 'Monday', 'Air'); |
| 295 | $this->table->add_row('John', 'Saturday', 'Overnight'); |
| 296 | |
AdwinTrave | 7428ff0 | 2014-06-04 17:44:17 -0500 | [diff] [blame] | 297 | echo $this->table->generate(); |