1313 <VInlineSwitch
1414 v-model =" item.raw.active"
1515 :align-items =" componentOptions.alignItems"
16- api-route =" api/posts"
1716 :cancel-button-color =" componentOptions.cancelButtonColor"
1817 :cancel-button-variant =" componentOptions.cancelButtonVariant"
1918 :cancel-icon =" componentOptions.cancelIcon"
2322 :color =" componentOptions.color"
2423 :density =" componentOptions.density"
2524 :disabled =" componentOptions.disabled"
26- :do-not-save =" componentOptions.doNotSave"
2725 :field-only =" componentOptions.fieldOnly"
2826 :icon-false =" componentOptions.iconFalse"
2927 :icon-false-title =" componentOptions.iconFalseTitle"
3028 :icon-true =" componentOptions.iconTrue"
3129 :icon-true-title =" componentOptions.iconTrueTitle"
3230 :item =" item"
3331 :label =" componentOptions.label"
32+ :loading =" item.raw.loading"
3433 name =" active"
3534 :underline-color =" componentOptions.underlineColor"
3635 :underline-style =" componentOptions.underlineStyle"
3736 :underline-width =" componentOptions.underlineWidth"
3837 :underlined =" componentOptions.underlined"
3938 @error =" showError = $event"
40- @loading =" loading = $event"
41- @update =" updatedValue($event, 'switch')"
39+ @update =" updatedValue(item.raw, 'reviewed')"
4240 />
4341 </template >
42+
4443 <template #[` item.userId ` ]=" { item } " >
4544 <VInlineSelect
4645 v-model =" item.raw.user"
4746 :align-items =" componentOptions.alignItems"
48- api-route =" api/posts"
4947 :cancel-button-color =" componentOptions.cancelButtonColor"
5048 :cancel-button-variant =" componentOptions.cancelButtonVariant"
5149 :cancel-icon-color =" componentOptions.cancelIconColor"
5452 :color =" componentOptions.color"
5553 :density =" componentOptions.density"
5654 :disabled =" componentOptions.disabled"
57- :do-not-save =" componentOptions.doNotSave"
5855 :empty-text =" componentOptions.emptyText"
5956 :field-only =" componentOptions.fieldOnly"
6057 :hide-details =" componentOptions.hideDetails"
6461 item-value =" id"
6562 :items =" users"
6663 :label =" componentOptions.label"
64+ :loading =" item.raw.loading"
6765 :menu =" componentOptions.menu"
68- name =" active "
66+ name =" userId "
6967 :return-object =" true"
7068 :save-button-color =" componentOptions.saveButtonColor"
7169 :save-icon =" componentOptions.saveIcon"
7775 :underlined =" componentOptions.underlined"
7876 :variant =" componentOptions.variant"
7977 @error =" showError = $event"
80- @loading =" loading = $event"
81- @update =" updatedValue($event, 'select')"
78+ @update =" updatedValue(item.raw, 'userId')"
8279 >
8380 </VInlineSelect >
8481 </template >
8784 <VInlineTextField
8885 v-model =" item.raw.title"
8986 :align-items =" componentOptions.alignItems"
90- api-route =" api/posts"
9187 :cancel-button-color =" componentOptions.cancelButtonColor"
9288 :cancel-button-variant =" componentOptions.cancelButtonVariant"
9389 :cancel-icon-color =" componentOptions.cancelIconColor"
9692 :color =" componentOptions.color"
9793 :density =" componentOptions.density"
9894 :disabled =" componentOptions.disabled"
99- :do-not-save =" componentOptions.doNotSave"
10095 :field-only =" componentOptions.fieldOnly"
10196 :hide-details =" componentOptions.hideDetails"
10297 :item =" item"
10398 :label =" componentOptions.label"
99+ :loading =" item.raw.loading"
104100 name =" title"
105101 required
106102 :save-button-color =" componentOptions.saveButtonColor"
113109 :underlined =" componentOptions.underlined"
114110 :variant =" componentOptions.variant"
115111 @error =" showError = $event"
116- @loading =" loading = $event"
117- @update =" updatedValue($event, 'text-field')"
112+ @update =" updatedValue(item.raw, 'title')"
118113 />
119114 </template >
120115
121116 <template #[` item.body ` ]=" { item } " >
122117 <VInlineTextarea
123118 v-model =" item.raw.body"
124119 :align-items =" componentOptions.alignItems"
125- api-route =" api/posts"
126120 :cancel-button-color =" componentOptions.cancelButtonColor"
127121 :cancel-button-variant =" componentOptions.cancelButtonVariant"
128122 :cancel-icon-color =" componentOptions.cancelIconColor"
131125 :color =" componentOptions.color"
132126 :density =" componentOptions.density"
133127 :disabled =" componentOptions.disabled"
134- :do-not-save =" componentOptions.doNotSave"
135128 :field-only =" componentOptions.fieldOnly"
136129 :hide-details =" false"
137130 :item =" item"
138131 :label =" componentOptions.label"
132+ :loading =" item.raw.loading"
139133 name =" body"
140134 :rules =" [componentOptions.rules.required, componentOptions.rules.minLength]"
141135 :save-button-color =" componentOptions.saveButtonColor"
148142 :underlined =" componentOptions.underlined"
149143 :variant =" componentOptions.variant"
150144 @error =" showError = $event"
151- @loading =" loading = $event"
152- @update =" updatedValue($event, 'textarea')"
145+ @update =" updatedValue(item.raw, 'body')"
153146 />
154147 </template >
155148
156149 <template #[` item.reviewed ` ]=" { item } " >
157150 <VInlineCheckbox
158151 v-model =" item.raw.reviewed"
159152 :align-items =" componentOptions.alignItems"
160- api-route =" api/posts"
161153 :cancel-button-color =" componentOptions.cancelButtonColor"
162154 :cancel-button-variant =" componentOptions.cancelButtonVariant"
163155 :cancel-icon-color =" componentOptions.cancelIconColor"
166158 :color =" componentOptions.color"
167159 :density =" componentOptions.density"
168160 :disabled =" componentOptions.disabled"
169- :do-not-save =" componentOptions.doNotSave"
170161 :field-only =" componentOptions.fieldOnly"
171162 :icon-false-title =" componentOptions.iconFalseTitle"
172163 :icon-true-title =" componentOptions.iconTrueTitle"
177168 :underline-width =" componentOptions.underlineWidth"
178169 :underlined =" componentOptions.underlined"
179170 @error =" showError = $event"
180- @loading =" loading = $event"
181- @update =" updatedValue($event, 'checkbox')"
171+ @update =" updatedValue(item.raw, 'reviewed')"
182172 />
183173 </template >
184174 </v-data-table >
@@ -218,11 +208,10 @@ const componentOptions = reactive({
218208 cancelIcon: undefined ,
219209 cancelIconColor: ' default' ,
220210 cancelIconText: ' Cancel' ,
221- closeSiblings: false ,
211+ closeSiblings: true ,
222212 color: ' primary' ,
223213 density: ' compact' ,
224214 disabled: false ,
225- doNotSave: false ,
226215 emptyText: ' empty' ,
227216 fieldOnly: false ,
228217 hideDetails: true ,
@@ -290,12 +279,14 @@ const headers = [
290279
291280let posts = ref ();
292281const users = ref (null );
293- const loading = ref (false );
294282const showError = ref (false );
283+ const apiPostsRoute = ' api/posts' ;
284+ const apiUsersRoute = ' api/users' ;
295285
296286function getPosts () {
297287 tableOptions .loading = true ;
298- fetch (' api/posts' )
288+
289+ fetch (apiPostsRoute)
299290 .then ((response ) => response .json ())
300291 .then ((json ) => {
301292 posts = [... json .posts ];
@@ -304,7 +295,7 @@ function getPosts() {
304295};
305296
306297function getUsers () {
307- fetch (' api/users ' )
298+ fetch (apiUsersRoute )
308299 .then ((response ) => response .json ())
309300 .then ((json ) => {
310301 users .value = json .users .map ((user ) => ({
@@ -314,17 +305,18 @@ function getUsers() {
314305 });
315306};
316307
308+
317309/**
318- * ? You can use this function to update the value in the database.
319- * ? Instead of using the internal axios call.
320- *
321- * @param {any} val
322- * @param {string} field
310+ * ? This is where you would save the item in the database.
323311 */
324- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
325- function updatedValue (val , field ) {
326- // Save updated values
327- console .log (' updatedValue' , val, field);
312+ function updatedValue (item , field ) {
313+ console .log (' PlaygroundPage.vue: updatedValue' , field, item);
314+ item .loading = true ;
315+
316+ // ? Simulate a delay while item is saving.
317+ setTimeout (() => {
318+ item .loading = false ;
319+ }, 1500 );
328320}
329321< / script>
330322
0 commit comments