46 | Table - Data
47 |
48 |
49 | Core table style.
50 | Compresses fluidly for small screens.
51 | Example: my orders, checkout summary.
52 |
53 |
54 |
55 |
56 |
57 | | Order # |
58 | Date |
59 | Total |
60 | Status |
61 | Action |
62 |
63 |
64 |
65 |
66 |
67 | | Primary Action |
68 |
69 |
70 |
71 |
72 |
73 | | 100000133 |
74 | 1/31/14 |
75 | $2,950.75 |
76 | Complete |
77 | View Order |
78 |
79 |
80 |
81 | | 100000131 |
82 | 1/31/14 |
83 | $80.76 |
84 | Pending |
85 | View Order |
86 |
87 |
88 |
89 | | 100000108 |
90 | 1/31/14 |
91 | $62.51 |
92 | Pending |
93 | View Order |
94 |
95 |
96 |
97 |
98 | Summary Tables
99 |
100 | In the example above, we have a "summary" table, which is a table that summarizes content and allows the user to take
101 | an action to view all the details. In a summary table, there are some columns that are more important than others.
102 | On smaller viewports, it is acceptable to hide the unessential columns, as the user can take an action to view
103 | full details. We hide unnecessary columns by using .data-p[1-4] classes to indicate the importance of
104 | a specific column. The .data-p* classes are then hidden on smaller viewports. The exact breakpoint at which a
105 | specific .data-p* class may vary, based on the context of the table.
106 |
107 |
108 | Example .data-p* classes
109 |
110 | .data-p1 {
111 | display:table-cell;
112 | }
113 |
114 | .data-p2,
115 | .data-p3,
116 | .data-p4 {
117 | display:none;
118 | }
119 |
120 | @include bp (min-width, 480px) {
121 |
122 | .data-p2 {
123 | display:table-cell;
124 | }
125 |
126 | }
127 |
128 | @include bp (min-width, 600px) {
129 |
130 | .data-p3 {
131 | display:table-cell;
132 | }
133 |
134 | }
135 |
136 | @include bp (min-width, 768px) {
137 |
138 | .data-p4 {
139 | display:table-cell;
140 | }
141 |
142 | }
143 |
144 | Table - Linearize
145 |
146 |
147 | Tables with many columns do not display well on small viewports. While hiding columns on *summary* tables is
148 | acceptable, it is not acceptable on data tables because users we should not restrict access to information
149 | based on viewport size. In order to display all of the data in this type of table without forcing the user to
150 | scroll, we use a "linearize" pattern that turns cells into rows.
151 |
152 |
153 | Example table
154 |
155 |
156 |
157 |
158 | |
159 | Product Name
160 | |
161 |
162 | SKU
163 | |
164 |
165 | Price
166 | |
167 |
168 | Qty
169 | |
170 |
171 | Subtotal
172 | |
173 |
174 |
175 |
176 |
177 | |
178 | Subtotal
179 | |
180 |
181 | $340.00
182 | |
183 |
184 |
185 | |
186 | Shipping & Handling
187 | |
188 |
189 | $15.00
190 | |
191 |
192 |
193 | |
194 | Grand Total
195 | |
196 |
197 | $355.00
198 | |
199 |
200 |
201 |
202 |
203 |
204 | Test Product #2
205 |
206 | -
207 | Color
208 |
209 | -
210 | Purple
211 |
212 |
213 | |
214 |
215 | Test Product-Purple
216 | |
217 |
218 | $140.00
219 | |
220 |
221 |
222 | -
223 | Ordered2
224 |
225 |
226 | |
227 |
228 | $240.00
229 | |
230 |
231 |
232 |
233 |
234 |
235 | Test Product
236 |
237 | -
238 | Color
239 |
240 | -
241 | Green
242 |
243 |
244 | |
245 |
246 | Test Product-Green
247 | |
248 |
249 | $120.00
250 | |
251 |
252 |
253 | -
254 | Ordered2
255 |
256 |
257 | |
258 |
259 | $240.00
260 | |
261 |
262 |
263 |
264 |
265 | |
266 | Bundled Product
267 | |
268 |
269 | Bundled Product-Test Product-Green
270 | |
271 |
272 | $100.00
273 | |
274 |
275 |
276 | |
277 |
278 | $100.00
279 | |
280 |
281 |
282 | |
283 |
284 | Laptop
285 |
286 | |
287 |
288 |
289 | |
290 | 1 x Test Product-Green $100.00
291 | |
292 |
293 | Test Product-Green
294 | |
295 |
296 |
297 | |
298 |
299 | Ordered: 1
300 | |
301 |
302 |
303 | |
304 |
305 |
306 |
307 |
308 | The markup for a linearized table follows this pattern
309 |
310 | <table class="linearize-table">
311 | <thead>
312 | <tr>
313 | <th>Product Name</th>
314 | <th>Price</th>
315 | </tr>
316 | </thead>
317 | <tbody>
318 | <tr>
319 | <-- The data-label attribute will be added via JS -->
320 | <td data-label="Product Name">Mountain Bike</td>
321 | <td data-label="Price">$3,000</td>
322 | </tr>
323 | <tr>
324 | <td data-label="Product Name">Helment</td>
325 | <td data-label="Price">$180</td>
326 | </tr>
327 | </tbody>
328 | </table>
329 |
330 |
331 | When a linearize table is displayed on a small viewport, the "data-label" attribute is used as the label for
332 | that cell
333 |
334 | .linearize-table tbody td[data-label]:before {
335 | content:attr(data-label) ":";
336 | }
337 |
338 | Rather than adding the data-label attribute to all tbody td elements, we have a jQuery decorator that does this for us
339 |
340 |
341 | The decorator allows us to write linearize table markup without the data-label attributes. This is useful because
342 | Magento has multiple item render template files, and using a decorator eliminates the need to update label/th values
343 | in multiple templates.
344 |
345 |
346 |
347 | In some linearized tables, the first column in the table does not need to be prepended with a label, as its
348 | meaning is apparent (eg, product name). For this type of column, a "data-no-label" attribute can be added to the
349 | th. You can see an example of this in the linearized table below.
350 |
351 |
352 | // ==============================================
353 | // UI Pattern - Linearize Table
354 | // ==============================================
355 |
356 | $('.linearize-table').each(function(){
357 |
358 | var cellLabels = [];
359 |
360 | // Loop through all table headers to find the labels
361 | $(this).find('thead th').each(function(index){
362 | // Only assign label if there is no data-no-label attribute on the th. Adding data-no-label will display
363 | // the value of each cell without it being prepended by a label, which can be useful for product name and
364 | // similar data types.
365 | cellLabels[index] = ($(this).is('[data-no-label]')) ? false : $(this).text().trim();
366 | });
367 |
368 | $(this).find('tbody tr').each(function(){
369 | // Looping through each td inside of each row so that the index value will match that of thead > tr > th
370 | $(this).children('td').each(function(index){
371 | var label = cellLabels[index];
372 | // As long as the th did not contain a data-no-label attribute, add the data-label attribute
373 | if (label) {
374 | $(this).attr('data-label', label);
375 | }
376 | });
377 | });
378 | });
379 |
380 | Using the JS decorator, we can now write our markup like this
381 |
382 | <table class="linearize-table">
383 | <thead>
384 | <tr>
385 | <th data-no-label>Product Name</th>
386 | <th>Price</th>
387 | <th>Qty</th>
388 | </tr>
389 | </thead>
390 | <tbody>
391 | <tr>
392 | <td>Mountain Bike</td>
393 | <td>$3,000</td>
394 | <td>2</td>
395 | </tr>
396 | <tr>
397 | <td>Helment</td>
398 | <td>$180</td>
399 | <td>1</td>
400 | </tr>
401 | </tbody>
402 | </table>
403 |
404 | Table - Linearize Custom
405 |
406 |
407 | For tables that are a more prominent part of the user experience (eg, cart items table), using a vanilla linearize
408 | pattern is not appropriate, as the screen real estate can be used in a more effective manner. For an example of
409 | this, reference the cart on the shop.angrybirds.com site.
410 |
411 |
412 |