vi-grid-builder 2.0.2 → 2.0.4

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,6 +1,33 @@
1
1
 
2
2
  # Grid builder plugin for Vue 3
3
3
 
4
+ The grid builder component dynamically generates tables based on the provided `rows` data and a JSON `columns` configuration.
5
+
6
+ ## Key Features
7
+
8
+ ### 1. Column Types
9
+ - **Predefined Types**:
10
+ - `text`: Displays plain text.
11
+ - `image`: Renders an image.
12
+ - `link`: Displays hyperlinks (with customizable text and URL behavior).
13
+ - `badge`: Displays styled labels or badges.
14
+ - `date`: Formats and displays dates.
15
+ - `actions`: Includes buttons or action elements.
16
+ - **Custom Types**:
17
+ - Register custom field types for unique cell content rendering.
18
+
19
+ ### 2. Data Handling
20
+ - Accepts data in the `rows` prop to populate the table.
21
+ - Supports cell-level customization for data formatting.
22
+
23
+ ### 3. Pagination
24
+ - Built-in pagination for handling large datasets.
25
+ - Configurable to match specific requirements (e.g., rows per page).
26
+
27
+ ### 4. Customizable Styles
28
+ - Provides options to style the table (e.g., striped rows, borders).
29
+ - Supports global configs and per-instance overrides.
30
+
4
31
 
5
32
  ## Installation
6
33
 
@@ -18,6 +45,15 @@ import App from './App.vue'
18
45
  const app = createApp(App).use(ViGridBuilder)
19
46
  ```
20
47
 
48
+ ## Examples
49
+ If you want to see usage examples download the project and run
50
+ ```sh
51
+ cd playgorund
52
+ ```
53
+ ```sh
54
+ npm run dev
55
+ ```
56
+
21
57
  ## Table options
22
58
 
23
59
  | option | type | description | default value |
@@ -59,13 +95,21 @@ const app = createApp(App).use(ViGridBuilder)
59
95
  | name | String | Name of the field for which data will be presented | / |
60
96
  | sortable | Boolean | Is the column sortable? | false |
61
97
  | isVisible | Boolean | Is the column visible? | true |
62
- | format | Function | Function to format the data before display | / |
98
+ | render | Function | Function to cange| format the data before display | / |
63
99
  | align | centre, left, right | How to align the content in the cells for this column | / |
64
100
  | sort | Function | Compare function for sorting data in this column | / |
65
- mode| date, dateTime, time| Option for date field | dateTime|
66
- format| String| Option for formatting the date field | yyyy-MM-dd HH:mm:ss
67
- actions |Array| Option for field of type action | /|
68
- link |String| Option for field of type link, this will be name of the field from which we need to get the link, and name attribute is for the text of the link| /
101
+
102
+ ## Aditional columsn options for sepcific fields
103
+
104
+ field type| option | type | description | default value |
105
+ |------------|------------|-----------------------------|--------------------------------------------------------|---------------|
106
+ |date | mode| date,time, dateTime| what part of the date shoudl be displayed| dateTime
107
+ |date | format| object | format of date field| {date:"yyyy-MM-dd",dateTime:"yyyy-MM-dd HH:mm:ss",time:"HH:mm:ss",}|
108
+ |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 |
109
+ |actions |kebab|boolean| should action menu be 'kebab type'| false |
110
+ |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.| /
111
+
112
+
69
113
 
70
114
  ## Example config for columns
71
115
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vi-grid-builder",
3
3
  "main": "ViGridBuilderPlugin",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -14,7 +14,7 @@
14
14
  "@fortawesome/free-solid-svg-icons": "^6.7.1",
15
15
  "@fortawesome/vue-fontawesome": "^3.0.8",
16
16
  "date-fns": "^2.30.0",
17
- "vi-pagination": "^1.0.0",
17
+ "vi-pagination": "^1.0.1",
18
18
  "vue": "^3.3.4"
19
19
  },
20
20
  "devDependencies": {
@@ -3,6 +3,8 @@
3
3
  <div>
4
4
  <h1> Examples</h1>
5
5
  </div>
6
+
7
+ <field-types/>
6
8
  <custom-header/>
7
9
 
8
10
 
@@ -49,10 +51,12 @@ import TableStyle from "@/components/TableStyle.vue";
49
51
  import PaginationOptions from "@/components/PaginationOptions.vue";
50
52
  import CustomField from "@/components/CustomField.vue";
51
53
  import GlobalOptions from "@/components/GlobalOptions.vue";
54
+ import FieldTypes from "@/components/FieldTypes.vue";
52
55
 
53
56
 
54
57
  export default {
55
58
  components: {
59
+ FieldTypes,
56
60
  GlobalOptions,
57
61
  CustomField,
58
62
  PaginationOptions,
@@ -0,0 +1,138 @@
1
+ <template>
2
+ <div class="example-container">
3
+
4
+ <h3 id="custom-header">Defautl field types</h3>
5
+ <div class="example-body">
6
+
7
+ <vi-grid-builder
8
+ stripped
9
+ v-bind="config"
10
+ v-model:pagination="config.pagination"
11
+ :rows="rows"
12
+ :server-mode="false"
13
+ />
14
+ </div>
15
+ </div>
16
+ </template>
17
+
18
+ <script>
19
+ import axios from "axios";
20
+
21
+ function getRandomDate(startDate, endDate) {
22
+ const start = new Date(startDate).getTime();
23
+ const end = new Date(endDate).getTime();
24
+ const randomTimestamp = Math.floor(Math.random() * (end - start + 1)) + start;
25
+ return new Date(randomTimestamp).toISOString();
26
+ }
27
+ const posts = Array.from({ length: 25 }, (_, index) => ({
28
+ id: index + 1,
29
+ title: `Post Title ${index + 1}`,
30
+ link: `https://example.com/post-${index + 1}`,
31
+ image: "https://images.pexels.com/photos/2325447/pexels-photo-2325447.jpeg",
32
+ status: Math.random() > 0.5 ? "published" : "unpublished",
33
+ date:getRandomDate("2020-01-01", "2024-12-31")
34
+ }));
35
+
36
+ console.log(posts);
37
+
38
+
39
+ export default {
40
+
41
+ data: () => ({
42
+
43
+ loading: true,
44
+ rows:posts,
45
+ config: {
46
+ rowKey: 'id',
47
+ columns: [{
48
+ label: 'ID',
49
+ name: 'id',
50
+
51
+ },
52
+ {
53
+ label: 'Title',
54
+ name: 'title',
55
+ },
56
+ {
57
+ label: 'Link',
58
+ name: 'link',
59
+ type:'link',
60
+ // link:'link'
61
+ },
62
+ {
63
+ label: 'Link with title',
64
+ name: 'title',
65
+ type:'link',
66
+ link:'link'
67
+ },
68
+ {
69
+ label: 'Image',
70
+ name: 'image',
71
+ type:'image'
72
+ },
73
+ {
74
+ label: 'Status',
75
+ name: 'status',
76
+ type:'badge'
77
+ },
78
+ {
79
+ label: 'Date',
80
+ name: 'date',
81
+ type:'date',
82
+ mode:'date'
83
+ },
84
+ {
85
+ label: 'Time',
86
+ name: 'date',
87
+ type:'date',
88
+ mode:'time'
89
+ },
90
+ {
91
+ label: 'Simple actions',
92
+ name: 'actions',
93
+ type:'actions',
94
+ actions:[
95
+ {
96
+ action:'edit',
97
+ name:'Edit post'
98
+ },
99
+ {
100
+ action:'remove',
101
+ name:'Remove post'
102
+ }
103
+ ]
104
+ },
105
+ {
106
+ label: 'Kebap type actions',
107
+ name: 'actions',
108
+ type:'actions',
109
+ kebab:true,
110
+ actions:[
111
+ {
112
+ action:'edit',
113
+ name:'Edit post'
114
+ },
115
+ {
116
+ action:'remove',
117
+ name:'Remove post'
118
+ }
119
+ ]
120
+ },
121
+ ],
122
+
123
+ pagination: {page: 1, rowsPerPage:15},
124
+
125
+ },
126
+ compact: false,
127
+
128
+ }),
129
+
130
+ }
131
+
132
+
133
+ </script>
134
+
135
+
136
+ <style scoped lang="scss">
137
+
138
+ </style>
@@ -11,9 +11,11 @@ app.use(ViGridBuilderPlugin, {
11
11
  fieldComponents: {
12
12
  SampleCustomField,
13
13
  },
14
+ dateFormats:{
15
+ time:'HH:mm'
16
+ },
14
17
 
15
18
  align: 'right',
16
- disablePagination: true,
17
19
 
18
20
  compactPagination: true,
19
21
  noDataLabel: 'emtpy tabled',
@@ -101,7 +101,7 @@
101
101
  <vi-grid-field
102
102
  :class="column.align ?? settings.align"
103
103
  :field="column"
104
- :field-value="column.format ? column.format(row) : row[column.name]"
104
+ :field-value="column.render ? column.render(row) : row[column.name]"
105
105
  :row-value="row"
106
106
  :row-key="rowKey"
107
107
  v-model:row-menu-opened="rowMenuOpened"
@@ -17,6 +17,9 @@ export default function useRowHelper(props, emit) {
17
17
  }
18
18
 
19
19
  let rowsPerPage = props.pagination?.rowsPerPage ?? globalGridSettings.value.rowsPerPage
20
+ if (rowsPerPage === 0) {
21
+ return sortedRows.value;
22
+ }
20
23
  const startIndex = (props.pagination.page - 1) * rowsPerPage;
21
24
  const endIndex = startIndex + rowsPerPage;
22
25
 
@@ -6,5 +6,8 @@
6
6
  line-height: 1;
7
7
  //font-weight: 600;
8
8
  text-transform: uppercase;
9
+ background-color: var(--vi-grid-primary-color);
10
+ color: var(--vi-grid-primary-text-color);
11
+ padding: 5px;
9
12
 
10
13
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="vi-grid-badge" v-bind="$attrs">
2
+ <div class="vi-grid-badge" v-bind="$attrs" :class="value">
3
3
  {{value}}
4
4
  </div>
5
5
  </template>
@@ -1,3 +1,7 @@
1
1
  .vi-grid-image {
2
2
 
3
+ img {
4
+ max-width: 100%;
5
+ max-height: 100px;
6
+ }
3
7
  }
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="vi-grid-link">
3
- <a :href="row[link]" target="_blank" v-if="row[link]">{{value}}</a>
3
+ <a :href="row[link] ?? value" target="_blank" v-if="(link && row[link]) || (!link && value)">{{value}}</a>
4
4
  <div v-else>{{value}}</div>
5
5
  </div>
6
6
  </template>
@@ -11,7 +11,7 @@
11
11
  props: {
12
12
  link: {
13
13
  type: String,
14
- required: true
14
+ // required: true
15
15
  },
16
16
  row: {
17
17
  type: Object,
@@ -1,18 +0,0 @@
1
- <template>
2
- <div class="vi-grid-number">
3
- {{value}}
4
- </div>
5
- </template>
6
-
7
- <script>
8
- export default {
9
- name: "ViGridNumber",
10
- props: {
11
- value: {},
12
- },
13
- }
14
- </script>
15
-
16
- <style lang="scss">
17
- @import "ViGridNumber";
18
- </style>