@@ -229,6 +229,33 @@ function addDocument() {
229229 selectedDocument .value [field ] = ' '
230230 }
231231 // }
232+
233+ // Scroll to new document and focus on first field
234+ setTimeout (() => {
235+ const tableEl = tableRef .value ?.$el as HTMLElement
236+ if (tableEl ) {
237+ // Scroll to the bottom where the new row is
238+ tableEl .scrollTop = tableEl .scrollHeight
239+ }
240+
241+ // Focus on the first editable field
242+ const firstField = fields .value .find (f => f !== ' _id' )
243+ if (firstField && selectedDocument .value ) {
244+ const inputId = ` ${selectedDocument .value ._id || ' new' }-${firstField } `
245+ const input = document .getElementById (inputId ) as HTMLInputElement
246+ if (input ) {
247+ input .focus ()
248+ }
249+ else {
250+ // If no _id yet, try to find the first input in the editing row
251+ setTimeout (() => {
252+ const firstInput = document .querySelector (' .custom-input input' ) as HTMLInputElement
253+ if (firstInput )
254+ firstInput .focus ()
255+ }, 100 )
256+ }
257+ }
258+ }, 100 )
232259}
233260
234261function editDocument(document : any ) {
@@ -316,85 +343,92 @@ useEventListener(tableRef, 'scroll', updateShadow)
316343 </script >
317344
318345<template >
319- <div class =" px-4 py-2 backdrop-blur z-10 flex items-center gap-4 border-b border-default" >
320- <UInput
321- v-model =" search"
322- placeholder =" Search..."
323- class =" flex-1"
324- />
325- <UButton
326- icon =" carbon:add"
327- color =" success"
328- @click =" addDocument"
329- >
330- Add Document
331- </UButton >
332- </div >
333-
334- <div
335- v-if =" totalDocuments"
336- class =" flex items-center px-4 py-2 border-b border-default"
337- >
338- <div class =" opacity-50" >
339- <span v-if =" search" >{{ filtered.length }} matched · </span >
340- <span >{{ documents?.length }} of {{ totalDocuments }} documents in total</span >
341- </div >
342- <div class =" flex-auto" />
343- <div class =" flex gap-2" >
344- <select
345- v-if =" pagination.limit !== 0"
346- v-model =" pagination.page"
347- class =" px-3 py-1.5 rounded border border-default bg-default"
346+ <NuxtLayout >
347+ <template #actions >
348+ <UInput
349+ v-model =" search"
350+ placeholder =" Search..."
351+ class =" w-64"
352+ />
353+ <UButton
354+ icon =" carbon:add"
355+ color =" success"
356+ @click =" addDocument"
348357 >
349- <option
350- v-for =" i in Math.ceil(totalDocuments / pagination.limit)"
351- :key =" i"
352- :value =" i"
358+ Add Document
359+ </UButton >
360+ </template >
361+
362+ <div
363+ v-if =" totalDocuments"
364+ class =" flex items-center px-4 py-2 border-b border-default"
365+ >
366+ <div class =" opacity-50" >
367+ <span v-if =" search" >{{ filtered.length }} matched · </span >
368+ <span >{{ documents?.length }} of {{ totalDocuments }} documents in total</span >
369+ </div >
370+ <div class =" flex-auto" />
371+ <div class =" flex gap-2" >
372+ <select
373+ v-if =" pagination.limit !== 0"
374+ v-model =" pagination.page"
375+ class =" px-3 py-1.5 rounded border border-default bg-default"
353376 >
354- page: {{ i }}
355- </ option >
356- </ select >
357- < select
358- v-model = " pagination.limit "
359- class = " px-3 py-1.5 rounded border border-default bg-default "
360- >
361- <option
362- v-for = " i in [1, 2, 3, 4, 5] "
363- :key = " i "
364- :value = " i * 10 "
377+ < option
378+ v-for = " i in Math.ceil(totalDocuments / pagination.limit) "
379+ :key = " i "
380+ :value = " i "
381+ >
382+ page: {{ i }}
383+ </ option >
384+ </ select >
385+ < select
386+ v-model = " pagination.limit "
387+ class = " px-3 py-1.5 rounded border border-default bg-default "
365388 >
366- show: {{ i * 10 }}
367- </option >
368- <option :value =" 0" >
369- show all
370- </option >
371- </select >
389+ <option
390+ v-for =" i in [1, 2, 3, 4, 5]"
391+ :key =" i"
392+ :value =" i * 10"
393+ >
394+ show: {{ i * 10 }}
395+ </option >
396+ <option :value =" 0" >
397+ show all
398+ </option >
399+ </select >
400+ </div >
372401 </div >
373- </div >
374-
375- <UTable
376- v-if =" documents?.length || selectedDocument"
377- ref =" tableRef"
378- v-model:column-pinning =" columnPinning"
379- :data =" tableData"
380- :columns =" columns"
381- sticky
382- :ui =" {
383- tr: editing ? 'data-[editing=true]:bg-elevated' : '',
384- }"
385- >
386- <template #_id-cell =" { row } " >
387- ObjectId('{{ row.original._id }}')
388- </template >
389- </UTable >
390-
391- <div
392- v-else
393- class =" flex justify-center items-center h-full text-2xl"
394- >
395- <span class =" mr-1" >📄</span >
396- No documents found
397- </div >
402+
403+ <UTable
404+ v-if =" documents?.length || selectedDocument"
405+ ref =" tableRef"
406+ v-model:column-pinning =" columnPinning"
407+ :data =" tableData"
408+ :columns =" columns"
409+ sticky
410+ :ui =" {
411+ tr: editing ? 'data-[editing=true]:bg-elevated' : '',
412+ }"
413+ >
414+ <template #_id-cell =" { row } " >
415+ <span v-if =" row.original._id" >
416+ ObjectId('{{ row.original._id }}')
417+ </span >
418+ <span v-else >
419+ ---
420+ </span >
421+ </template >
422+ </UTable >
423+
424+ <div
425+ v-else
426+ class =" flex justify-center items-center h-full text-2xl"
427+ >
428+ <span class =" mr-1" >📄</span >
429+ No documents found
430+ </div >
431+ </NuxtLayout >
398432</template >
399433
400434<style lang="scss">
0 commit comments