vi-grid-builder 2.1.0 → 2.1.2

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,261 +49,417 @@ 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
- columns: [
120
- {
130
+ columns: [{
121
131
  label: 'ID',
122
- type: 'vi-grid-text',
123
132
  name: 'id',
133
+ type: 'number',
124
134
  sortable: true,
125
- align: 'right'
135
+ },
136
+ {
137
+ label: 'Title',
138
+ name: 'title',
126
139
  },
127
140
  {
128
- label: 'Name',
129
- type: 'vi-grid-text',
130
- name: 'user',
131
- format: (row) => `${row.firstName} ${row.lastName}`,
132
- align: 'center'
141
+ label: 'Link',
142
+ name: 'link',
143
+ type: 'link',
144
+ // link:'link'
133
145
  },
134
146
  {
135
- label: 'Hidden column',
136
- type: 'vi-grid-text',
137
- name: 'title',
138
- isVisible: false // This can be a function as well
147
+ label: 'Link with title',
148
+ name: 'title',
149
+ type: 'link',
150
+ link: 'link'
139
151
  },
140
152
  {
141
- label: 'Hidden column with custom rule',
142
- type: 'vi-grid-text',
143
- name: 'title',
144
- isVisible: () => user.role === 'member'
145
- }
153
+ label: 'Price',
154
+ name: 'price',
155
+ type: 'number',
156
+ sortable: true,
157
+ format: {
158
+ style: 'currency',
159
+ currency: 'USD',
160
+ }
161
+ },
162
+ {
163
+ label: 'Image',
164
+ name: 'image',
165
+ type: 'image'
166
+ },
167
+ {
168
+ label: 'Status',
169
+ name: 'status',
170
+ type: 'badge'
171
+ },
172
+ {
173
+ label: 'Date',
174
+ name: 'date',
175
+ type: 'date',
176
+ mode: 'date'
177
+ },
178
+ {
179
+ label: 'Time',
180
+ name: 'date',
181
+ type: 'date',
182
+ },
183
+ {
184
+ label: 'Simple actions',
185
+ name: 'actions',
186
+ type: 'actions',
187
+ actions: [
188
+ {
189
+ action: 'edit',
190
+ name: 'Edit post'
191
+ },
192
+ {
193
+ action: 'remove',
194
+ name: 'Remove post'
195
+ }
196
+ ]
197
+ },
198
+ {
199
+ label: 'Kebab type actions',
200
+ name: 'actions',
201
+ type: 'actions',
202
+ kebab: true,
203
+ actions: [
204
+ {
205
+ action: 'edit',
206
+ name: 'Edit post'
207
+ },
208
+ {
209
+ action: 'remove',
210
+ name: 'Remove post'
211
+ }
212
+ ]
213
+ },
146
214
  ]
147
215
  ```
148
216
 
149
217
  ## 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
218
+
219
+ | name | description | props
220
+ |------------|---------------------------------------------------------------|------------|
221
+ | empty-data | slot for when no data in table | /
222
+ | loading | slot for displaying loading when data is fetching from server | /
223
+ | footer | slot for overriding footer of table | pagination
155
224
 
156
225
  ## 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:
226
+
227
+ By default the gird builder for displaying data in the cells supports the following types of fields : **text**, **link
228
+ **, **image**, **date** , **badge**, **actions** and **checkbox**?. If this fields does not full-fill the needs for you
229
+ application you can register your own type of fields.
230
+ 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
231
+ will display the user's initials.
232
+ First we need to create the component for the new field, and then we need to define it in the options for the plugin.
233
+ Props that you will receive for the custom field are:
160
234
 
161
235
  - **field** - all options for the column
162
- - **value** - value for the field or '/' if no value
163
- - **original-value** - original value for the field
236
+ - **value** - value for the field or '/' if no value
237
+ - **original-value** - original value for the field
164
238
  - **row** - value for the whole row (ex if the table display name and id of a user, that row would be one user)
165
239
 
166
- The componenet can look like this
240
+ The component can look like this
241
+
242
+ ```vue
167
243
 
168
- ```js
169
244
  <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>
245
+ <div class="avatar">
246
+ <img v-if="row.picture"
247
+ :src="row.picture" alt="User Avatar" class="avatar-img"/>
248
+ <div v-else class="avatar-initials">{{initials}}</div>
249
+ </div>
174
250
  </template>
175
251
 
176
252
  <script>
177
- export default {
178
- name: 'UserAvatar',
179
- props: {
180
- field: {
181
- type: Object,
182
- },
183
- value: {},
184
- originalValue: {},
185
- row: {
186
- type: Object,
187
- }
188
- },
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('');
194
- }
195
- return '';
196
- }
197
- }
198
- };
253
+ export default {
254
+ name: 'UserAvatar',
255
+ props: {
256
+ field: {
257
+ type: Object,
258
+ },
259
+ value: {},
260
+ originalValue: {},
261
+ row: {
262
+ type: Object,
263
+ }
264
+ },
265
+ computed: {
266
+ initials() {
267
+ if (this.row.name) {
268
+ const nameParts = this.row.name.split(' ');
269
+ return nameParts.map(part => part[0].toUpperCase()).join('');
270
+ }
271
+ return '';
272
+ }
273
+ }
274
+ };
199
275
  </script>
200
276
  ```
277
+
201
278
  Then we need to add this component as part of the settings for the plugin.
202
279
  See example:
203
280
 
204
- ```js
281
+ ```javascript
205
282
  import UserAvatar from "./components/user/UserAvatar.vue";
206
283
  import ViGridBuilder from "vi-grid-builder";
207
284
 
208
285
  const app = createApp(App)
209
- .use(ViGridBuilder, {
210
- fieldComponents:{
211
- UserAvatar
212
- }
213
- })
286
+ .use(ViGridBuilder, {
287
+ fieldComponents: {
288
+ UserAvatar
289
+ }
290
+ })
291
+ ```
214
292
 
215
- After adding the component in the fieldComponents we can use the new field type in the definition for the columns, like this :
293
+ After adding the component in the fieldComponents we can use the new field type in the definition for the columns, like
294
+ this
216
295
 
296
+ ```javascript
217
297
  columns: [
218
- {
219
- label: 'User',
220
- type: 'user-avatar',
221
- name: 'picture',
222
- }]
298
+ {
299
+ label: 'User',
300
+ type: 'user-avatar',
301
+ name: 'picture',
302
+ }]
223
303
  ```
224
304
 
225
-
226
305
  ## Pagination
227
306
 
228
307
  Pagination is passed as object in table prop, the obejct should have this fields:
229
308
 
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
309
+ | name | type | description | default value
310
+ |-------------|------------------|--------------------------------------------------------|---------------|
311
+ | page | Number | number for the current page | /
312
+ | rowsPerPage | Number | number of rows displayed per page | 10
313
+ | rowsNumber | Number | number of total avaliable rows - only for server side | /
314
+ | sortBy | array of objects | sort by field and direction | null
236
315
 
316
+ ## Pagination otpions
237
317
 
318
+ | name | type | description | default value
319
+ |--------------------|------------------|--------------------------------------------------------|---------------|
320
+ | disablePagination | Boolean | hide pagination | false
321
+ | compactPagination | Boolean | should the pagination be compact (no pages displayed) | false
322
+ | rowsPerPageOptions | Array of obecjts | Droprdown options for displayin how many rows per page | /
238
323
 
324
+ ## CSS CLASSES
239
325
 
326
+ | class name | description
327
+ |-----------------------------|------------------------------------------------------------------------|
328
+ | .vi-table-container | wrapper around table |
329
+ | .vi-table-container.loading | classes for loading state of table |
330
+ | .vi-table | class for the table tag |
331
+ | .vi-table.stripped | class used to apply alternating background colors to table rows |
332
+ | .vi-table.bordered | class used to apply borders on table cells |
333
+ | .vi-table-head | class for the head tag |
334
+ | .vi-table-body | class for the tbody tag |
335
+ | .vi-table-row | class for all rows in table |
336
+ | .vi-header-row | class for rows only in table header |
337
+ | .vi-body-row | class for rows only in table body |
338
+ | .vi-body-row.selected | class for selected row |
339
+ | .vi-body-row.clickable | class for clickable row |
340
+ | .vi-title-row | class for row that displays the table tite |
341
+ | .vi-loading-row | class for row that holds the loading bar |
342
+ | .vi-no-data-row | class for row that appears when no data is avaliable in table |
343
+ | .vi-cell | class for all cells in table |
344
+ | .vi-header-cell | class for header cells in table |
345
+ | .vi-body-cell | class for body cells in table |
346
+ | .vi-header-cell-content | class that wrapes content in header cells |
347
+ | .vi-select-cell | class for cells that holds checkbox for selecting row or master select |
348
+ | .vi-grid-field | wraaper clas for content in body cells |
349
+ | .vi-footer-row | class for last row in table that holds usually pagination |
350
+ | .vi-footer-cell | class for cell in last row |
351
+
352
+ ## GLOBAL SETTINGS
353
+
354
+ ### **Grid props that can be set globally**
355
+
356
+ - align: `center`, `left`,`right`
357
+ - bordered: boolean
358
+ - stripped: boolean
359
+ - disablePagination: boolean
360
+ - noDataLabel: String
361
+ - noCellDataLabel: String
362
+ - compactPagination: boolean
363
+ - rowsPerPageOptions: Array
364
+
365
+ Example:
366
+
367
+ ```javascript
240
368
 
241
- ## Pagination otpions
369
+ import {createApp} from 'vue'
370
+ import App from './App.vue'
242
371
 
372
+ const app = createApp(App);
373
+ app.use(ViGridBuilderPlugin, {
374
+ align: 'right',
375
+ compactPagination: true,
376
+ noDataLabel: 'emtpy table data',
377
+ noCellDataLabel: 'NA',
378
+ stripped: true,
379
+ bordered: true,
380
+ rowsPerPage: 30,
381
+ rowsPerPageOptions: [{
382
+ label: 15,
383
+ value: 15
384
+ }, {
385
+ label: 20,
386
+ value: 20
387
+ }, {
388
+ label: 30,
389
+ value: 30
390
+ }, {
391
+ label: 'all',
392
+ value: 0
393
+ }],
394
+ });
395
+
396
+
397
+ app.mount('#app')
243
398
 
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| /
399
+ ```
249
400
 
401
+ ### **Date field global settings**
250
402
 
251
- ## CSS CLASSES
403
+ You can globally set format for date field by passing `dateFormats` in the plugin options
404
+ You can globally set mode for date field by passing `dateMode` in the plugin options (one of `date` , `dateTime`,
405
+ `time` by default is `dateTime`)
252
406
 
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)
407
+ ```javascript
408
+ const app = createApp(App);
409
+ app.use(ViGridBuilderPlugin, {
410
+
411
+ dateFormats: {
412
+ time: 'HH:mm',
413
+ date: "yyyy-MM-dd",
414
+ dateTime: "yyyy-MM-dd HH:mm:ss"
415
+ },
416
+ dateMode: 'date'
417
+ });
418
+ ```
419
+
420
+ ### **Css variables and global overwriting of the variables**
421
+
422
+ | name | usage | default value
423
+ |------------------------------|---------------------------------------------------------------------|-----------------------|
424
+ | --vi-grid-primary-color | background color of header and used as backgorund for rows on hover | rgba(0, 0, 255, 0.65)
425
+ | --vi-grid-primary-text_color | text color of header and used as text color for rows on hover | rgb(255, 255, 255)
426
+ | --vi-grid-secondary-color | background color even rows in stripped table | rgb(243, 243, 243)
427
+ | --vi-grid-text-color | color of text in tabel body cells | rgb(0, 0, 0)
428
+ | --vi-grid-color | background color for table | rgb(255, 255, 255)
288
429
 
289
430
  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: {
431
+
432
+ ```javascript
433
+
434
+ const app = createApp(App);
435
+ app.use(ViGridBuilderPlugin, {
436
+ style:
437
+ {
295
438
  'color': 'white',
296
439
  'text-color': 'black',
297
440
  'secondary-color': 'lightgrey',
298
441
  'primary-color': '#f18080',
299
442
  'primary-text-color': 'white',
300
- }
301
- });
443
+ }
444
+ })
302
445
  ```
303
446
 
447
+ ### Steps for adding changes for contributors
448
+
449
+ - git pull origin main
450
+ - add and test your changes in playground
451
+ - change the version in package.json
452
+ - vite build
453
+ - push to git
454
+ - npm publish
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
304
463
 
305
464
 
306
465