Skip to content

Commit aa77a93

Browse files
committed
updated readme with custom classes & vbt-classes
1 parent 6753c65 commit aa77a93

File tree

1 file changed

+92
-21
lines changed

1 file changed

+92
-21
lines changed

README.md

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77

8+
89
# 1. vue-bootstrap4-table
910

1011
> Advanced table based on Vue 2 and Bootstrap 4
@@ -885,12 +886,82 @@ Each action object should contain the below attributes.
885886
| event_name | Name of the event that you want to listen back (Mandatory)| String | undefined |
886887
| event_payload | Payload you want to send with the event | Any | undefined |
887888

889+
# 13. Custom classes
888890

889-
# 13. Config
890-
You can optionally pass config as a prop to **`vue-bootstrap4-table`** component to override the table configuration defaults.
891+
You can pass your classes for the table, row, cell, etc.. via **`classes`** prop. And interesting thing is you can pass a validator function to apply custom classes conditionally.
891892

892893
## 13.1. Example
893894
```vue
895+
<template>
896+
<div id="app">
897+
<vue-bootstrap4-table :classes="classes"
898+
:rows="rows"
899+
:columns="columns">
900+
</vue-bootstrap4-table>
901+
</div>
902+
</template>
903+
904+
<script>
905+
import VueBootstrap4Table from 'vue-bootstrap4-table'
906+
export default {
907+
name: 'App',
908+
data: function() {
909+
return {
910+
rows: [
911+
...
912+
],
913+
columns: [
914+
...
915+
],
916+
classes: {
917+
table : {
918+
"table-striped my-class" : true,
919+
"table-bordered my-class-two" : function(rows) {
920+
return true
921+
}
922+
},
923+
row : {
924+
"my-row my-row2" : true,
925+
"function-class" : function(row) {
926+
return row.id == 1
927+
}
928+
},
929+
cell : {
930+
"my-cell my-cell2" : true,
931+
"text-danger" : function(row,column,cellValue) {
932+
return column.name == "salary" && row.salary > 2500
933+
}
934+
}
935+
}
936+
}
937+
},
938+
components: {
939+
VueBootstrap4Table
940+
}
941+
}
942+
</script>
943+
```
944+
Currently you can add custom classes to **`<table>, <tr> and <td>`** elements using table, row, and cell properties respectively.
945+
946+
You can either pass the custom classes directly or pass a function with your condition check to decide whether to apply to class or not.
947+
948+
For example, in the above example, look at the property **`cell`**. There we are applying classes **"my-cell my-cell2"** directly to **`<td>`** element and **"text-danger"** class only to the "salary" column & also the salary value should be above 2500.
949+
950+
# 14. vbt-classes
951+
By default, vue-bootstrap-table add classes to table elements which allows users to override the default styles.
952+
## 14.1. vbt-row-selected
953+
If a row is being selected with checkbox or row, then the selected row <tr> element will have "vbt-row-selected" class attached to it.
954+
955+
```html
956+
<tr class="vbt-row-selected">
957+
...
958+
</tr>
959+
```
960+
# 15. Config
961+
You can optionally pass config as a prop to **`vue-bootstrap4-table`** component to override the table configuration defaults.
962+
963+
## 15.1. Example
964+
```vue
894965
<template>
895966
<div id="app">
896967
<vue-bootstrap4-table :rows="rows" :columns="columns" :config="config">
@@ -945,7 +1016,7 @@ You can optionally pass config as a prop to **`vue-bootstrap4-table`** component
9451016

9461017
> If you don't provide an attribute in the config, then default value will be assigned to that attribute.
9471018
948-
## 13.2. Attributes details
1019+
## 15.2. Attributes details
9491020

9501021
|Attributes | Description | type| Default |
9511022
|--|--|--|--|
@@ -969,11 +1040,11 @@ You can optionally pass config as a prop to **`vue-bootstrap4-table`** component
9691040
| show_reset_button | Show/Hide Refresh button. Resets all query (sort, filter, global search) currently applied in the table. |Boolean | true |
9701041
| server_mode | Enable/Disable server side processing (Sorting, Filtering, Global search & pagination) |Boolean | false |
9711042

972-
# 14. Server mode
1043+
# 16. Server mode
9731044

9741045
In server mode, client side filtering, sorting, global search and pagination will be disabled. Instead your server will do all this and returns only the processed response. New response will update the rows in the table.
9751046

976-
## 14.1. Example
1047+
## 16.1. Example
9771048

9781049
```vue
9791050
<template>
@@ -1049,7 +1120,7 @@ In server mode, client side filtering, sorting, global search and pagination wil
10491120
</style>
10501121
```
10511122

1052-
### 14.1.1. Step 1
1123+
### 16.1.1. Step 1
10531124

10541125
In your application you should have the below information in **`data.`**
10551126

@@ -1064,7 +1135,7 @@ queryParams: {
10641135
total_rows: 0,
10651136
```
10661137

1067-
### 14.1.2. Step 2
1138+
### 16.1.2. Step 2
10681139

10691140
If you want to work with pagination, then don't forget to set **`total_rows`** as prop to **`totalRows`**.
10701141

@@ -1079,7 +1150,7 @@ Then listen for the event **`on-change-query`**.
10791150
</vue-bootstrap4-table>
10801151
```
10811152

1082-
### 14.1.3. Step 3
1153+
### 16.1.3. Step 3
10831154

10841155
Wherever there is a change in table query params, you will get your new query params in your **`onChangeQuery`** function. With the new values update your **`queryParams`** and fetch new data from server.
10851156

@@ -1090,7 +1161,7 @@ onChangeQuery(queryParams) {
10901161
},
10911162
```
10921163

1093-
### 14.1.4. Step 4
1164+
### 16.1.4. Step 4
10941165

10951166
I assume you are using **`axios`** library for handling ajax requests.
10961167

@@ -1114,7 +1185,7 @@ fetchData() {
11141185
});
11151186
}
11161187
```
1117-
### 14.1.5. Note
1188+
### 16.1.5. Note
11181189
To get best performance, it is recommended to mention in column config that which column have unique values. You can refer the below example.
11191190
```javascript
11201191
columns: [
@@ -1132,55 +1203,55 @@ columns: [
11321203
...
11331204
]
11341205
```
1135-
# 15. Events
1206+
# 17. Events
11361207

1137-
## 15.1. on-select-row
1208+
## 17.1. on-select-row
11381209

11391210
Triggered after selecting a row.
11401211

1141-
### 15.1.1. Payload (Object)
1212+
### 17.1.1. Payload (Object)
11421213

11431214
| Attribute| Description |
11441215
|--|--|
11451216
|selected_items | List of currently selected rows |
11461217
| selected_item | Currently selected item |
11471218

1148-
## 15.2. on-all-select-rows
1219+
## 17.2. on-all-select-rows
11491220

11501221
Triggers after clicking select all check box.
11511222

1152-
### 15.2.1. Payload (Object)
1223+
### 17.2.1. Payload (Object)
11531224

11541225
| Attribute| Description |
11551226
|--|--|
11561227
|selected_items | List of currently selected rows |
11571228

1158-
## 15.3. on-unselect-row
1229+
## 17.3. on-unselect-row
11591230

11601231
Triggered after deselecting a row.
11611232

1162-
### 15.3.1. Payload (Object)
1233+
### 17.3.1. Payload (Object)
11631234

11641235
| Attribute| Description |
11651236
|--|--|
11661237
|selected_items | List of currently selected rows |
11671238
| unselected_item |Currently deselected item |
11681239

1169-
## 15.4. on-all-unselect-rows
1240+
## 17.4. on-all-unselect-rows
11701241

11711242
Triggers after clicking deselect all check box.
11721243

1173-
### 15.4.1. Payload (Object)
1244+
### 17.4.1. Payload (Object)
11741245

11751246
| Attribute| Description |
11761247
|--|--|
11771248
|selected_items | List of currently selected rows |
11781249

1179-
## 15.5. refresh-data
1250+
## 17.5. refresh-data
11801251

11811252
Triggers after clicking refresh button. This event doesn't carry any payload.
11821253

1183-
# 16. Build Setup
1254+
# 18. Build Setup
11841255

11851256
``` bash
11861257
# install dependencies

0 commit comments

Comments
 (0)