Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div>
  3.     <v-data-table
  4.       id="timesheets-table"
  5.       :headers="headers"
  6.       :items="rows"
  7.       class="elevation-1"
  8.       hide-actions
  9.     >
  10.       <template v-slot:items="props">
  11.         <td>
  12.           <v-autocomplete
  13.             class="study-autocomplete"
  14.             v-model="props.item.study"
  15.             :items="studies"
  16.             label="Search for a study..."
  17.             persistent-hint
  18.             prepend-icon="book"
  19.             item-text="text"
  20.             item-value="id"
  21.           ></v-autocomplete>
  22.         </td>
  23.         <td class="day-col">
  24.           <v-text-field
  25.             type="number"
  26.             step="0.5"
  27.             min="0"
  28.             max="7.5"
  29.             :input-value="props.item.mondayInput"
  30.             v-model="props.item.mondayInput"
  31.             placeholder="e.g. 7.5"
  32.           ></v-text-field>
  33.         </td>
  34.         <td class="day-col">
  35.           <v-text-field
  36.             type="number"
  37.             step="0.5"
  38.             min="0"
  39.             max="7.5"
  40.             :input-value="props.item.tuesdayInput"
  41.             v-model="props.item.tuesdayInput"
  42.           ></v-text-field>
  43.         </td>
  44.         <td class="day-col">
  45.           <v-text-field
  46.             type="number"
  47.             step="0.5"
  48.             min="0"
  49.             max="7.5"
  50.             :input-value="props.item.wednesdayInput"
  51.             v-model="props.item.wednesdayInput"
  52.           ></v-text-field>
  53.         </td>
  54.         <td class="day-col">
  55.           <v-text-field
  56.             type="number"
  57.             step="0.5"
  58.             min="0"
  59.             max="7.5"
  60.             :input-value="props.item.thursdayInput"
  61.             v-model="props.item.thursdayInput"
  62.           ></v-text-field>
  63.         </td>
  64.         <td class="day-col">
  65.           <v-text-field
  66.             type="number"
  67.             step="0.5"
  68.             min="0"
  69.             max="7.5"
  70.             :input-value="props.item.fridayInput"
  71.             v-model="props.item.fridayInput"
  72.           ></v-text-field>
  73.         </td>
  74.         <td class="day-col">
  75.           <v-text-field
  76.             type="number"
  77.             step="0.5"
  78.             min="0"
  79.             max="7.5"
  80.             :input-value="props.item.saturdayInput"
  81.             v-model="props.item.saturdayInput"
  82.           ></v-text-field>
  83.         </td>
  84.         <td class="day-col">
  85.           <v-text-field
  86.             type="number"
  87.             step="0.5"
  88.             min="0"
  89.             max="7.5"
  90.             :input-value="props.item.sundayInput"
  91.             v-model="props.item.sundayInput"
  92.           ></v-text-field>
  93.         </td>
  94.         <td>
  95.           <v-btn flat icon color="red" @click.prevent="removeRow(props.item)">
  96.             <v-icon>close</v-icon>
  97.           </v-btn>
  98.         </td>
  99.       </template>
  100.     </v-data-table>
  101.     <div class="text-xs-center pt-2">
  102.       <v-btn color="primary" @click.prevent="addRow">Add Row</v-btn>
  103.       <v-btn
  104.         :disabled="!rows.length"
  105.         color="secondary"
  106.         @click.prevent="submitTimesheets"
  107.       >
  108.         Submit
  109.       </v-btn>
  110.     </div>
  111.   </div>
  112. </template>
  113.  
  114. <script>
  115. export default {
  116.   name: 'timesheets',
  117.   data: () => ({
  118.     studies: [
  119.       { id: 1, text: 'TICTOC' },
  120.       { id: 2, text: 'PIMP' },
  121.       { id: 3, text: 'Core Work' },
  122.       { id: 4, text: 'TARS' },
  123.       { id: 5, text: 'MYRIAD' }
  124.     ],
  125.     headers: [
  126.       {
  127.         text: 'Study',
  128.         sortable: false,
  129.         value: 'study'
  130.       },
  131.       {
  132.         text: 'Monday',
  133.         sortable: false,
  134.         value: 'monday-input'
  135.       },
  136.       {
  137.         text: 'Tuesday',
  138.         sortable: false,
  139.         value: 'tuesday-input'
  140.       },
  141.       {
  142.         text: 'Wednesday',
  143.         sortable: false,
  144.         value: 'wednesday-input'
  145.       },
  146.       {
  147.         text: 'Thursday',
  148.         sortable: false,
  149.         value: 'thursday-input'
  150.       },
  151.       {
  152.         text: 'Friday',
  153.         sortable: false,
  154.         value: 'friday-input'
  155.       },
  156.       {
  157.         text: 'Saturday',
  158.         sortable: false,
  159.         value: 'saturday-input'
  160.       },
  161.       {
  162.         text: 'Sunday',
  163.         sortable: false,
  164.         value: 'sunday-input'
  165.       },
  166.       {
  167.         text: 'Actions',
  168.         sortable: false
  169.       }
  170.     ],
  171.     rows: [
  172.       {
  173.         rowNumber: 1,
  174.         study: null,
  175.         mondayInput: '',
  176.         tuesdayInput: '',
  177.         wednesdayInput: '',
  178.         thursdayInput: '',
  179.         fridayInput: '',
  180.         saturdayInput: '',
  181.         sundayInput: ''
  182.       },
  183.       {
  184.         rowNumber: 2,
  185.         study: null,
  186.         mondayInput: '',
  187.         tuesdayInput: '',
  188.         wednesdayInput: '',
  189.         thursdayInput: '',
  190.         fridayInput: '',
  191.         saturdayInput: '',
  192.         sundayInput: ''
  193.       }
  194.     ]
  195.   }),
  196.   methods: {
  197.     addRow() {
  198.       let newRowNum = this.rows.length + 1;
  199.  
  200.       this.rows.push({
  201.         rowNumber: newRowNum,
  202.         study: null,
  203.         mondayInput: '',
  204.         tuesdayInput: '',
  205.         wednesdayInput: '',
  206.         thursdayInput: '',
  207.         fridayInput: '',
  208.         saturdayInput: '',
  209.         sundayInput: ''
  210.       });
  211.     },
  212.     removeRow(row) {
  213.       console.log(row);
  214.       this.rows = this.rows.filter(obj => obj.rowNumber !== row.rowNumber);
  215.     },
  216.     submitTimesheets() {
  217.       console.log(this.rows);
  218.       this.$toast.success('Timesheet data saved successfully');
  219.     }
  220.   }
  221. };
  222. </script>
  223.  
  224. <style lang="scss" scoped>
  225. .study-autocomplete {
  226.   min-width: 160px;
  227. }
  228.  
  229. // .day-col {
  230. //   min-width: 120px;
  231. // }
  232.  
  233. #timesheets-table {
  234.   table.v-datatable.v-table {
  235.     table-layout: fixed;
  236.   }
  237. }
  238. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement