fixed-header-with-fluid-header.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <el-table :data="tableData" style="width: 100%" max-height="250">
  3. <el-table-column fixed prop="date" label="Date" width="150" />
  4. <el-table-column prop="name" label="Name" width="120" />
  5. <el-table-column prop="state" label="State" width="120" />
  6. <el-table-column prop="city" label="City" width="120" />
  7. <el-table-column prop="address" label="Address" width="600" />
  8. <el-table-column prop="zip" label="Zip" width="120" />
  9. <el-table-column fixed="right" label="Operations" width="120">
  10. <template #default="scope">
  11. <el-button
  12. link
  13. type="primary"
  14. size="small"
  15. @click.prevent="deleteRow(scope.$index)"
  16. >
  17. Remove
  18. </el-button>
  19. </template>
  20. </el-table-column>
  21. </el-table>
  22. <el-button class="mt-4" style="width: 100%" @click="onAddItem"
  23. >Add Item</el-button
  24. >
  25. </template>
  26. <script lang="ts" setup>
  27. import { ref } from 'vue'
  28. import dayjs from 'dayjs'
  29. const now = new Date()
  30. const tableData = ref([
  31. {
  32. date: '2016-05-01',
  33. name: 'Tom',
  34. state: 'California',
  35. city: 'Los Angeles',
  36. address: 'No. 189, Grove St, Los Angeles',
  37. zip: 'CA 90036',
  38. },
  39. {
  40. date: '2016-05-02',
  41. name: 'Tom',
  42. state: 'California',
  43. city: 'Los Angeles',
  44. address: 'No. 189, Grove St, Los Angeles',
  45. zip: 'CA 90036',
  46. },
  47. {
  48. date: '2016-05-03',
  49. name: 'Tom',
  50. state: 'California',
  51. city: 'Los Angeles',
  52. address: 'No. 189, Grove St, Los Angeles',
  53. zip: 'CA 90036',
  54. },
  55. ])
  56. const deleteRow = (index: number) => {
  57. tableData.value.splice(index, 1)
  58. }
  59. const onAddItem = () => {
  60. now.setDate(now.getDate() + 1)
  61. tableData.value.push({
  62. date: dayjs(now).format('YYYY-MM-DD'),
  63. name: 'Tom',
  64. state: 'California',
  65. city: 'Los Angeles',
  66. address: 'No. 189, Grove St, Los Angeles',
  67. zip: 'CA 90036',
  68. })
  69. }
  70. </script>