You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(table): Refactor field formatter support + optimized sort-compare handling (#991)
* refactor(b-table): use original item object
* chore(table.spec): eslint format
* feat(b-table): Allow usr provided sortCopmpare to handle only specific fields
if user provided sortCompare returns `null` (or `undefined`), then we assume it doesn't handle sorting for the field specified by `sortBy`
* ESLint
* Always return formattedValue as `value` in scoped slot.
Unformatted value is available as property `unformatted` on scoped slot data.
* Update docs
* Update README.md
* Allow formattter to return html content
* Update README.md
* fix(table-docs): unexpected identifier error
* fix(table-docs): typo corrections ⌨💥
* Allow v-html without need for wrapper div via v-if/v-else
@@ -212,21 +212,21 @@ When fields is provided as an object, the following field properties are availab
212
212
| Property | Type | Description
213
213
| ---------| ---- | -----------
214
214
| `class` | String or Array | Class name (or array of class names) to add to `<th>`**and**`<td>` in the column
215
-
| `formatter` | String or Function | A formatter callback function, can be used instead of slots for real table fields (i.e. fields, that have corresponding data at items array).
215
+
| `formatter` | String or Function | A formatter callback function, can be used instead of (or in conjunction with) slots for real table fields (i.e. fields, that have corresponding data at items array).
216
216
| `label` | String | Appears in the columns table header (and footer if `foot-clone` is set). Defaults to the field's key
217
217
| `sortable` | Boolean | Enable sorting on this column
218
218
| `tdClass` | String or Array | Class name (or array of class names) to add to data `<td>` cells in the column
219
219
| `thClass` | String or Array | Class name (or array of class names) to add to header/footer `<th>` cell
220
220
| `thStyle` | Object | JavaScript object representing CSS styles you would like to apply to the table field `<th>`
221
-
| `variant` | String | Apply contextual class to the `<th>`**and**`<td>` in the column (`active`, `success`, `info`, `warning`, `danger`)
221
+
| `variant` | String | Apply contextual class to the `<th>`**and**`<td>` in the column - `active`, `success`, `info`, `warning`, `danger` (these variants map to classes `thead-${variant}`, `table-${variant}`, or `bg-${variant}` accordingly)
222
222
223
-
>**Notes:**
224
-
>-_Field properties, if not present, default to `null` unless otherwise stated above._
225
-
>-_`thClass` and `tdClass` will not work with classes that are defined in scoped CSS_
226
-
>-_For information on the syntax supported by `thStyle`, see
223
+
**Notes:**
224
+
-_Field properties, if not present, default to `null` unless otherwise stated above._
225
+
-_`thClass` and `tdClass` will not work with classes that are defined in scoped CSS_
226
+
-_For information on the syntax supported by `thStyle`, see
227
227
[Class and Style Bindings](https://vuejs.org/v2/guide/class-and-style.html#Binding-Inline-Styles)
228
228
in the Vue.js guide._
229
-
>-_Any additional properties added to the field objects will be left intact - so you can access
229
+
-_Any additional properties added to the field objects will be left intact - so you can access
230
230
them via the named scoped slots for custom data, header, and footer rendering._
231
231
232
232
For information and usage about scoped slots and formatters, refer to
@@ -306,20 +306,17 @@ The slot's scope variable (`data` in the above sample) will have the following p
306
306
| Property | Type | Description
307
307
| -------- | ---- | -----------
308
308
| `index` | Number | The row number (indexed from zero)
309
-
| `item` | Object | The entire record (i.e. `items[index]`) for this row (deep clone)
310
-
| `value` | Any | The value for this key in the record (`null` or `undefined` if a virtual column)
309
+
| `item` | Object | The entire raw record data (i.e. `items[index]`) for this row (before any formatter is applied)
310
+
| `value` | Any | The value for this key in the record (`null` or `undefined` if a virtual column), or the output of thr field's `formatter` function (see below for for information on field `formatter` callback functions)
311
+
| `unformatted` | Any | The raw value for this key in the item record (`null` or `undefined` if a virtual column), before being passed to the field's `formtter` function
311
312
312
313
313
-
>**Note:***`index` will not always be the actual row's index number, as it is
314
+
**Notes:**
315
+
-*`index` will not always be the actual row's index number, as it is
314
316
computed after pagination and filtering have been applied to the original
315
317
table data. The `index` value will refer to the **displayed row number**. This
316
318
number will align with the indexes from the optional `v-model` bound variable.*
317
-
318
-
`<b-table>` always deep clones the items array data before pagination, sorting,
319
-
filtering and display. Hence any changes made to the item data passed to
320
-
the custom rendered slot will **not** affect the original provided items array.
321
-
322
-
When placing inputs, buttons, selects or links within a data cell scoped slot,
319
+
- When placing inputs, buttons, selects or links within a data cell scoped slot,
323
320
be sure to add a `@click.stop` handler (which can be empty) to prevent the
324
321
click on the input, button, select, or link, from triggering the `row-clicked`
325
322
event:
@@ -335,20 +332,23 @@ event:
335
332
336
333
One more option to customize field output is to use formatter callback function.
337
334
To enable this field's property `formatter` is used. Value of this property may be
338
-
String or function reference. In case of String value, function must be defined at parent component's methods,
339
-
to provide formatter as `Function`, it must be declared at global scope (window or as global mixin at Vue).
335
+
String or function reference. In case of a String value, function must be defined at
336
+
parent component's methods. Providing formatter as `Function`, it must be declared at
337
+
global scope (window or as global mixin at Vue).
340
338
341
-
Callback function accepts three arguments - `value`, `key`, `row`.
339
+
Callback function accepts three arguments - `value`, `key`, and `item`, and should
340
+
return the formatted value as a string (basic HTML is supported)
342
341
343
342
**Example 6: Custom data rendering with formatter callback function**
0 commit comments