vi-grid-builder 2.0.9 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
-
2
1
  # Grid builder plugin for Vue 3
3
2
 
4
- The grid builder component dynamically generates tables based on the provided `rows` data and a JSON `columns` configuration.
3
+ The grid builder component dynamically generates tables based on the provided `rows` data and a JSON `columns`
4
+ configuration.
5
5
 
6
6
  ## Key Features
7
7
 
8
8
  ### 1. Column Types
9
+
9
10
  - **Predefined Types**:
10
11
  - `text`: Displays plain text and if sortabel sorted alphabetically.
11
12
  - `number`: Displays number that can be formtated with NumberFormatOptions and sorted numerically .
@@ -18,18 +19,20 @@ The grid builder component dynamically generates tables based on the provided `r
18
19
  - Register custom field types for unique cell content rendering.
19
20
 
20
21
  ### 2. Data Handling
22
+
21
23
  - Accepts data in the `rows` prop to populate the table.
22
24
  - Supports cell-level customization for data formatting.
23
25
 
24
26
  ### 3. Pagination
27
+
25
28
  - Built-in pagination for handling large datasets.
26
29
  - Configurable to match specific requirements (e.g., rows per page).
27
30
 
28
31
  ### 4. Customizable Styles
32
+
29
33
  - Provides options to style the table (e.g., striped rows, borders).
30
34
  - Supports global configs and per-instance overrides.
31
35
 
32
-
33
36
  ## Installation
34
37
 
35
38
  ```sh
@@ -46,158 +49,174 @@ import App from './App.vue'
46
49
  const app = createApp(App).use(ViGridBuilder)
47
50
  ```
48
51
 
52
+ Import the style
53
+
54
+ ```html
55
+ @import "vi-grid-builder/style.css";
56
+ ```
57
+
49
58
  ## Examples
59
+
50
60
  If you want to see usage examples download the project and run
61
+
51
62
  ```sh
52
63
  cd playgorund
53
64
  ```
65
+
54
66
  ```sh
55
67
  npm run dev
56
68
  ```
57
69
 
58
70
  ## Table options
59
71
 
60
- | option | type | description | default value |
61
- |------------|-----------------------------|--------------------------------------------------------|---------------|
62
- |rows| Array | Data that needs to be displayed in the table| /
63
- |row-key|String| Name of the field that is unique identifier for a single row|/
64
- |columns| Array| Config for the column (in details below)|/
65
- |title| String | Title for the table | /
66
- |pagination|Object| Pagination config for the rows| in detilas under pagination section
67
- |rowsNumber| Number| Total number of rows| /
68
- |disable-pagination| Boolean| Option to hide pagination| false
69
- |server-mode| Boolean | Is data fetched from server| true
70
- |fetch-server-data| Function | Function that will fetch data from server|/
71
- |fetch-on-init| Boolean| On initialisation make request to fetch data| true
72
- |filter|fdf|fdf|fr
73
- |loading| Boolean| For server side **loading** is handled, for client side you can you this prop| false
74
- |no-data-label| String| Text to display when there is no data in the table|No data found
75
- |no-cell-data-label| String| Text to display if there is no value for the cell| "/" is displayed by default
76
- |clcikable-row| Boolean| emits rowClicked event with row as argumnet|false
72
+ | option | type | description | default value |
73
+ |--------------------|----------|-------------------------------------------------------------------------------|-------------------------------------|
74
+ | rows | Array | Data that needs to be displayed in the table | /
75
+ | row-key | String | Name of the field that is unique identifier for a single row | /
76
+ | columns | Array | Config for the column (in details below) | /
77
+ | title | String | Title for the table | /
78
+ | pagination | Object | Pagination config for the rows | in detilas under pagination section
79
+ | rowsNumber | Number | Total number of rows | /
80
+ | disable-pagination | Boolean | Option to hide pagination | false
81
+ | server-mode | Boolean | Is data fetched from server | true
82
+ | fetch-server-data | Function | Function that will fetch data from server | /
83
+ | fetch-on-init | Boolean | On initialisation make request to fetch data | true
84
+ | filter | fdf | fdf | fr
85
+ | loading | Boolean | For server side **loading** is handled, for client side you can you this prop | false
86
+ | no-data-label | String | Text to display when there is no data in the table | No data found
87
+ | no-cell-data-label | String | Text to display if there is no value for the cell | "/" is displayed by default
88
+ | clcikable-row | Boolean | emits rowClicked event with row as argumnet | false
77
89
 
78
90
  ## Header options
79
91
 
80
- | option | type | decsription | default value
81
- |--|--| --| --
82
- | title | String | title for the table | /
92
+ | option | type | decsription | default value
93
+ |--------|--------|---------------------|---------------
94
+ | title | String | title for the table | /
83
95
 
84
96
  ## Header slots
85
- |name | description | props
86
- |--|--| --|
87
- | title | slot for displaying title on top of the table| title
88
- | vi-header-cell-[column_name] | slot for override default header cell for each column| column
97
+
98
+ | name | description | props
99
+ |------------------------------|--------------------------------------------------------|--------|
100
+ | title | slot for displaying title on top of the table | title
101
+ | vi-header-cell-[column_name] | slot for override default header cell for each column | column
89
102
 
90
103
  ## Columns options
91
104
 
92
- | option | type | description | default value |
93
- |------------|-----------------------------|--------------------------------------------------------|---------------|
94
- | label | String | Title for the column | / |
95
- |type| text, link, image, date, badge, actions| Type of the field| text
96
- | name | String | Name of the field for which data will be presented | / |
97
- | sortable | Boolean | Is the column sortable? | false |
98
- | isVisible | Boolean | Is the column visible? | true |
99
- | render | Function | Function to cange| format the data before display | / |
100
- | align | centre, left, right | How to align the content in the cells for this column | / |
101
- | sort | Function | Compare function for sorting data in this column | / |
105
+ | option | type | description | default value |
106
+ |-----------|------------------------------------------|-------------------------------------------------------|--------------------------------|
107
+ | label | String | Title for the column | / |
108
+ | type | text, link, image, date, badge, actions | Type of the field | text
109
+ | name | String | Name of the field for which data will be presented | / |
110
+ | sortable | Boolean | Is the column sortable? | false |
111
+ | isVisible | Boolean | Is the column visible? | true |
112
+ | render | Function | Function to cange | format the data before display | / |
113
+ | align | centre, left, right | How to align the content in the cells for this column | / |
114
+ | sort | Function | Compare function for sorting data in this column | / |
102
115
 
103
116
  ## Aditional columsn options for sepcific fields
104
117
 
105
- field type| option | type | description | default value |
106
- |------------|------------|-----------------------------|--------------------------------------------------------|---------------|
107
- |date | mode| date,time, dateTime| what part of the date shoudl be displayed| dateTime
108
- |date | format| object | format of date field| {date:"yyyy-MM-dd",dateTime:"yyyy-MM-dd HH:mm:ss",time:"HH:mm:ss",} `date-fns` is used for formtatiin|
109
- |actions |actions|Array of object| Option for field of type action | every object should have unique action field and name for the text displayed for the action |
110
- |actions |kebab|boolean| should action menu be 'kebab type'| false |
111
- |link |String| link field| If the link field is provided, it is used as the URL, and name is used as the link text. If the link field is not provided, both the URL and link text default to the name field value.| /
112
- |number | format| object - NumberFormatOptions| format of number field| ex: {style: 'currency',currency: 'USD'}|
113
-
114
-
118
+ field type | option | type | description | default value |
119
+ |------------|---------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
120
+ | date | mode | date,time, dateTime | what part of the date shoudl be displayed | dateTime
121
+ | date | format | object | format of date field | {date:"yyyy-MM-dd",dateTime:"yyyy-MM-dd HH:mm:ss",time:"HH:mm:ss",} `date-fns` is used for formtatiin |
122
+ | actions | actions | Array of object | Option for field of type action | every object should have unique action field and name for the text displayed for the action |
123
+ | actions | kebab | boolean | should action menu be 'kebab type' | false |
124
+ | link | String | link field | If the link field is provided, it is used as the URL, and name is used as the link text. If the link field is not provided, both the URL and link text default to the name field value. | /
125
+ | number | format | object - NumberFormatOptions | format of number field | ex: {style: 'currency',currency: 'USD'} |
115
126
 
116
127
  ## Example config for columns
117
128
 
118
129
  ```js
119
130
  columns: [
120
131
  {
121
- label: 'ID',
122
- type: 'vi-grid-text',
123
- name: 'id',
124
- sortable: true,
125
- align: 'right'
132
+ label: 'ID',
133
+ type: 'vi-grid-text',
134
+ name: 'id',
135
+ sortable: true,
136
+ align: 'right'
126
137
  },
127
138
  {
128
- label: 'Name',
129
- type: 'vi-grid-text',
130
- name: 'user',
131
- format: (row) => `${row.firstName} ${row.lastName}`,
132
- align: 'center'
139
+ label: 'Name',
140
+ type: 'vi-grid-text',
141
+ name: 'user',
142
+ format: (row) => `${row.firstName} ${row.lastName}`,
143
+ align: 'center'
133
144
  },
134
145
  {
135
- label: 'Hidden column',
136
- type: 'vi-grid-text',
137
- name: 'title',
138
- isVisible: false // This can be a function as well
146
+ label: 'Hidden column',
147
+ type: 'vi-grid-text',
148
+ name: 'title',
149
+ isVisible: false // This can be a function as well
139
150
  },
140
151
  {
141
- label: 'Hidden column with custom rule',
142
- type: 'vi-grid-text',
143
- name: 'title',
144
- isVisible: () => user.role === 'member'
152
+ label: 'Hidden column with custom rule',
153
+ type: 'vi-grid-text',
154
+ name: 'title',
155
+ isVisible: () => user.role === 'member'
145
156
  }
146
157
  ]
147
158
  ```
148
159
 
149
160
  ## Table body slots
150
- |name | description | props
151
- |--|--| --|
152
- | empty-data | slot for when no data in table| /
153
- | loading | slot for displaying loading when data is fetching from server| /
154
- |footer | slot for overriding footer of table | pagination
161
+
162
+ | name | description | props
163
+ |------------|---------------------------------------------------------------|------------|
164
+ | empty-data | slot for when no data in table | /
165
+ | loading | slot for displaying loading when data is fetching from server | /
166
+ | footer | slot for overriding footer of table | pagination
155
167
 
156
168
  ## Registering custom field type
157
- By default the gird builder for displaying data in the cells supports the following types of fields : **text**, **link**, **image**, **date** , **badge**, **actions** and **checkbox**?. If this fields does not full-fill the needs for you application you can register your own type of fields.
158
- For example if we need an "avatar" field that will display the user's picture and if there is no picture for the user it will display the user's initials.
159
- First we need to create the component for the new field, and then we need to define it in the options for the plugin. Props that you will receive for the custom field are:
169
+
170
+ By default the gird builder for displaying data in the cells supports the following types of fields : **text**, **link
171
+ **, **image**, **date** , **badge**, **actions** and **checkbox**?. If this fields does not full-fill the needs for you
172
+ application you can register your own type of fields.
173
+ For example if we need an "avatar" field that will display the user's picture and if there is no picture for the user it
174
+ will display the user's initials.
175
+ First we need to create the component for the new field, and then we need to define it in the options for the plugin.
176
+ Props that you will receive for the custom field are:
160
177
 
161
178
  - **field** - all options for the column
162
- - **value** - value for the field or '/' if no value
163
- - **original-value** - original value for the field
179
+ - **value** - value for the field or '/' if no value
180
+ - **original-value** - original value for the field
164
181
  - **row** - value for the whole row (ex if the table display name and id of a user, that row would be one user)
165
182
 
166
- The componenet can look like this
183
+ The component can look like this
167
184
 
168
185
  ```js
169
186
  <template>
170
- <div class="avatar">
171
- <img v-if="row.picture" :src="row.picture" alt="User Avatar" class="avatar-img" />
172
- <div v-else class="avatar-initials">{{ initials }}</div>
173
- </div>
187
+ <div class="avatar">
188
+ <img v-if="row.picture"
189
+ :src="row.picture" alt="User Avatar" class="avatar-img" />
190
+ <div v-else class="avatar-initials">{{initials}}</div>
191
+ </div>
174
192
  </template>
175
193
 
176
194
  <script>
177
- export default {
178
- name: 'UserAvatar',
179
- props: {
180
- field: {
181
- type: Object,
195
+ export default {
196
+ name: 'UserAvatar',
197
+ props: {
198
+ field: {
199
+ type: Object,
182
200
  },
183
- value: {},
184
- originalValue: {},
185
- row: {
186
- type: Object,
201
+ value: {},
202
+ originalValue: {},
203
+ row: {
204
+ type: Object,
187
205
  }
188
206
  },
189
- computed: {
190
- initials() {
191
- if (this.row.name) {
192
- const nameParts = this.row.name.split(' ');
193
- return nameParts.map(part => part[0].toUpperCase()).join('');
207
+ computed: {
208
+ initials() {
209
+ if (this.row.name) {
210
+ const nameParts = this.row.name.split(' ');
211
+ return nameParts.map(part => part[0].toUpperCase()).join('');
194
212
  }
195
- return '';
213
+ return '';
196
214
  }
197
215
  }
198
216
  };
199
217
  </script>
200
218
  ```
219
+
201
220
  Then we need to add this component as part of the settings for the plugin.
202
221
  See example:
203
222
 
@@ -206,101 +225,194 @@ import UserAvatar from "./components/user/UserAvatar.vue";
206
225
  import ViGridBuilder from "vi-grid-builder";
207
226
 
208
227
  const app = createApp(App)
209
- .use(ViGridBuilder, {
210
- fieldComponents:{
211
- UserAvatar
212
- }
213
- })
214
-
215
- After adding the component in the fieldComponents we can use the new field type in the definition for the columns, like this :
228
+ .use(ViGridBuilder, {
229
+ fieldComponents: {
230
+ UserAvatar
231
+ }
232
+ })
233
+
234
+ After
235
+ adding
236
+ the
237
+ component in the
238
+ fieldComponents
239
+ we
240
+ can
241
+ use
242
+ the
243
+ new field
244
+ type in the
245
+ definition
246
+ for the columns, like
247
+ this
248
+ :
216
249
 
217
250
  columns: [
218
- {
219
- label: 'User',
220
- type: 'user-avatar',
221
- name: 'picture',
222
- }]
251
+ {
252
+ label: 'User',
253
+ type: 'user-avatar',
254
+ name: 'picture',
255
+ }]
223
256
  ```
224
257
 
225
-
226
258
  ## Pagination
227
259
 
228
260
  Pagination is passed as object in table prop, the obejct should have this fields:
229
261
 
230
- |name |type| description | default value
231
- |--|--|--|--|
232
- | page | Number|number for the current page| /
233
- | rowsPerPage | Number|number of rows displayed per page| 10
234
- |rowsNumber | Number| number of total avaliable rows - only for server side| /
235
- |sortBy | array of objects | sort by field and direction| null
262
+ | name | type | description | default value
263
+ |-------------|------------------|--------------------------------------------------------|---------------|
264
+ | page | Number | number for the current page | /
265
+ | rowsPerPage | Number | number of rows displayed per page | 10
266
+ | rowsNumber | Number | number of total avaliable rows - only for server side | /
267
+ | sortBy | array of objects | sort by field and direction | null
268
+
269
+ ## Pagination otpions
270
+
271
+ | name | type | description | default value
272
+ |--------------------|------------------|--------------------------------------------------------|---------------|
273
+ | disablePagination | Boolean | hide pagination | false
274
+ | compactPagination | Boolean | should the pagination be compact (no pages displayed) | false
275
+ | rowsPerPageOptions | Array of obecjts | Droprdown options for displayin how many rows per page | /
236
276
 
277
+ ## CSS CLASSES
237
278
 
279
+ | class name | description
280
+ |-----------------------------|------------------------------------------------------------------------|
281
+ | .vi-table-container | wrapper around table |
282
+ | .vi-table-container.loading | classes for loading state of table |
283
+ | .vi-table | class for the table tag |
284
+ | .vi-table.stripped | class used to apply alternating background colors to table rows |
285
+ | .vi-table.bordered | class used to apply borders on table cells |
286
+ | .vi-table-head | class for the head tag |
287
+ | .vi-table-body | class for the tbody tag |
288
+ | .vi-table-row | class for all rows in table |
289
+ | .vi-header-row | class for rows only in table header |
290
+ | .vi-body-row | class for rows only in table body |
291
+ | .vi-body-row.selected | class for selected row |
292
+ | .vi-body-row.clickable | class for clickable row |
293
+ | .vi-title-row | class for row that displays the table tite |
294
+ | .vi-loading-row | class for row that holds the loading bar |
295
+ | .vi-no-data-row | class for row that appears when no data is avaliable in table |
296
+ | .vi-cell | class for all cells in table |
297
+ | .vi-header-cell | class for header cells in table |
298
+ | .vi-body-cell | class for body cells in table |
299
+ | .vi-header-cell-content | class that wrapes content in header cells |
300
+ | .vi-select-cell | class for cells that holds checkbox for selecting row or master select |
301
+ | .vi-grid-field | wraaper clas for content in body cells |
302
+ | .vi-footer-row | class for last row in table that holds usually pagination |
303
+ | .vi-footer-cell | class for cell in last row |
304
+
305
+ ## GLOBAL SETTINGS
306
+
307
+ ### **Grid props that can be set globally**
308
+
309
+ - align: `center`, `left`,`right`
310
+ - bordered: boolean
311
+ - stripped: boolean
312
+ - disablePagination: boolean
313
+ - noDataLabel: String
314
+ - noCellDataLabel: String
315
+ - compactPagination: boolean
316
+ - rowsPerPageOptions: Array
317
+
318
+ Example:
319
+
320
+ ```javascript
238
321
 
322
+ import {createApp} from 'vue'
323
+ import App from './App.vue'
239
324
 
325
+ const app = createApp(App);
326
+ app.use(ViGridBuilderPlugin, {
327
+ align: 'right',
328
+ compactPagination: true,
329
+ noDataLabel: 'emtpy table data',
330
+ noCellDataLabel: 'NA',
331
+ stripped: true,
332
+ bordered: true,
333
+ rowsPerPage: 30,
334
+ rowsPerPageOptions: [{
335
+ label: 15,
336
+ value: 15
337
+ }, {
338
+ label: 20,
339
+ value: 20
340
+ }, {
341
+ label: 30,
342
+ value: 30
343
+ }, {
344
+ label: 'all',
345
+ value: 0
346
+ }],
347
+ });
348
+
349
+
350
+ app.mount('#app')
240
351
 
241
- ## Pagination otpions
352
+ ```
242
353
 
354
+ ### **Date field global settings**
243
355
 
244
- |name | type| description | default value
245
- |--|--| --|--|
246
- |disablePagination | Boolean| hide pagination | false
247
- | compactPagination | Boolean| should the pagination be compact (no pages displayed) | false
248
- | rowsPerPageOptions |Array of obecjts| Droprdown options for displayin how many rows per page| /
356
+ You can globally set format for date field by passing `dateFormats` in the plugin options
357
+ You can globally set mode for date field by passing `dateMode` in the plugin options (one of `date` , `dateTime`,
358
+ `time` by default is `dateTime`)
249
359
 
360
+ ```javascript
361
+ const app = createApp(App);
362
+ app.use(ViGridBuilderPlugin, {
250
363
 
251
- ## CSS CLASSES
364
+ dateFormats: {
365
+ time: 'HH:mm',
366
+ date: "yyyy-MM-dd",
367
+ dateTime: "yyyy-MM-dd HH:mm:ss"
368
+ },
369
+ dateMode: 'date'
370
+ });
371
+ ```
372
+
373
+ ### **Css variables and global overwriting of the variables**
252
374
 
253
- |class name | description
254
- |--|--|
255
- | .vi-table-container | wrapper around table|
256
- | .vi-table-container.loading| classes for loading state of table|
257
- | .vi-table | class for the table tag|
258
- | .vi-table.stripped | class used to apply alternating background colors to table rows|
259
- | .vi-table.bordered | class used to apply borders on table cells|
260
- | .vi-table-head | class for the head tag|
261
- | .vi-table-body | class for the tbody tag|
262
- | .vi-table-row| class for all rows in table|
263
- | .vi-header-row| class for rows only in table header|
264
- | .vi-body-row| class for rows only in table body|
265
- | .vi-body-row.selected| class for selected row|
266
- | .vi-body-row.clickable| class for clickable row|
267
- | .vi-title-row| class for row that displays the table tite|
268
- | .vi-loading-row| class for row that holds the loading bar|
269
- | .vi-no-data-row| class for row that appears when no data is avaliable in table|
270
- | .vi-cell| class for all cells in table|
271
- | .vi-header-cell| class for header cells in table|
272
- | .vi-body-cell| class for body cells in table|
273
- | .vi-header-cell-content| class that wrapes content in header cells|
274
- | .vi-select-cell| class for cells that holds checkbox for selecting row or master select|
275
- | .vi-grid-field| wraaper clas for content in body cells|
276
- | .vi-footer-row| class for last row in table that holds usually pagination|
277
- | .vi-footer-cell| class for cell in last row|
278
-
279
- ## CSS VARIBALES
280
-
281
- |name | usage | default value
282
- |--|--|--|
283
- |--vi-grid-primary-color | background color of header and used as backgorund for rows on hover| rgba(0, 0, 255, 0.65)
284
- |--vi-grid-primary-text_color | text color of header and used as text color for rows on hover| rgb(255, 255, 255)
285
- | --vi-grid-secondary-color | background color even rows in stripped table|rgb(243, 243, 243)
286
- | --vi-grid-text-color | color of text in tabel body cells|rgb(0, 0, 0)
287
- | --vi-grid-color |background color for table|rgb(255, 255, 255)
375
+ | name | usage | default value
376
+ |------------------------------|---------------------------------------------------------------------|-----------------------|
377
+ | --vi-grid-primary-color | background color of header and used as backgorund for rows on hover | rgba(0, 0, 255, 0.65)
378
+ | --vi-grid-primary-text_color | text color of header and used as text color for rows on hover | rgb(255, 255, 255)
379
+ | --vi-grid-secondary-color | background color even rows in stripped table | rgb(243, 243, 243)
380
+ | --vi-grid-text-color | color of text in tabel body cells | rgb(0, 0, 0)
381
+ | --vi-grid-color | background color for table | rgb(255, 255, 255)
288
382
 
289
383
  You can override this values in the options when plugin is installed:
290
- ```js
291
- const app = createApp(App);
292
- app.use(ViGridBuilderPlugin, {
293
- ...
294
- style: {
384
+
385
+ ```javascript
386
+
387
+ const app = createApp(App);
388
+ app.use(ViGridBuilderPlugin, {
389
+ style:
390
+ {
295
391
  'color': 'white',
296
392
  'text-color': 'black',
297
393
  'secondary-color': 'lightgrey',
298
394
  'primary-color': '#f18080',
299
395
  'primary-text-color': 'white',
300
- }
301
- });
396
+ }
397
+ })
302
398
  ```
303
399
 
400
+ ### Steps for adding changes for contributors
401
+
402
+ - git pull origin main
403
+ - add and test your changes in playground
404
+ - change the version in package.json
405
+ - vite build
406
+ - push to git
407
+ - npm publish
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
304
416
 
305
417
 
306
418