Advertisement
weeez

Custom Vue Table

Jul 4th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div>
  3.         <table class="pds-table-wrapper">
  4.             <!-- Header -->
  5.             <thead>
  6.                 <tr class="pds-table-row-header">
  7.                     <th v-for="(item, index) in columns" :key="index + 456">{{item.label}}</th>
  8.                 </tr>
  9.             </thead>
  10.  
  11.             <!-- Datas -->
  12.             <tbody>
  13.                 <tr v-for="(data, index) in showData" :key="index + 345" class="pds-table-row pds-table-row-small">
  14.                     <td v-for="(column, iter) in columns" :key="iter + 92">{{data[column.field]}}</td>
  15.                 </tr>
  16.             </tbody>
  17.         </table>
  18.         <div id="pds-pagination" class="pds-table-pagination-wrapper">
  19.             <div class="pds-pagination-container">
  20.                 <div class="pds-pagination-state-box" v-for="(item, index) in innerData" :key="index + 7155">
  21.                     <p class="pds-pagination-state-box-label">
  22.                         {{index + 1}}
  23.                     </p>
  24.                 </div>
  25.             </div>
  26.         </div>
  27.     </div>
  28. </template>
  29.  
  30. <script>
  31.     export default {
  32.         props:{
  33.             'columns': {
  34.                 type: Array,
  35.                 default: []
  36.             },
  37.             'data': {
  38.                 type: Array,
  39.                 default: []
  40.             },
  41.             'size': {
  42.                 type: Number,
  43.                 default: 5
  44.             },
  45.             'isPaginated': {
  46.                 type: Boolean,
  47.                 default: false
  48.             }
  49.         },
  50.         created(){
  51.             if(this.isPaginated){
  52.                 let currentSize = this.size;
  53.                 let splitCounter= this.data.length;
  54.                 if(splitCounter > currentSize){
  55.                     while(splitCounter > currentSize){
  56.                         splitCounter -= currentSize;
  57.                         this.innerData.push(this.data.splice(0, this.size));
  58.                     }                        
  59.                 }                  
  60.             }
  61.             this.innerData.push(this.data);
  62.  
  63.             this.showData = [];
  64.             this.showData = this.innerData[this.currentIndex].slice();
  65.         },
  66.         watch:{
  67.             data(){
  68.                 console.log('kecskefészek')
  69.                 console.log(this.data)
  70.             }
  71.         },
  72.         data(){
  73.             return {
  74.                 innerData: [],
  75.                 showData: [],
  76.                 currentIndex: 0
  77.             }
  78.         }
  79.     }
  80. </script>
  81.  
  82. <style lang="scss"scoped>
  83.     @import "../../css/pds.scss";
  84.  
  85.     $main-border-color: #e0d9d9;
  86.     $main-font-color: #363636;
  87.     $header-title-font-size: 14px;
  88.     $table-cells-font-size: 12px;
  89.     $table-row-line-height: 40px;
  90.  
  91.     .pds-table-wrapper{
  92.         width: 100%;
  93.         font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  94.         color: $main-font-color;
  95.         //border: 1px solid $main-border-color;
  96.         font-size: $table-cells-font-size;
  97.     }
  98.  
  99.  
  100.     //header css
  101.     .pds-table-row-header{
  102.         border-bottom: outset $main-border-color;
  103.     }
  104.  
  105.     .pds-table-wrapper th {
  106.         font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  107.         text-align: center;
  108.         color: $main-font-color;
  109.         font-size: $header-title-font-size;
  110.         border-bottom: inset $main-border-color;
  111.     }
  112.     .pds-table-wrapper th:nth-child(1) {
  113.         border-bottom: outset $main-border-color;
  114.     }    
  115.  
  116.     //body css
  117.     .pds-table-wrapper tr{
  118.         font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  119.         text-align: center;
  120.         line-height: $table-row-line-height;
  121.         font-size: $table-cells-font-size;
  122.         border-bottom: 1px solid $main-border-color;
  123.     }
  124.  
  125.     .pds-table-wrapper tr:last-child{
  126.         border-bottom: none;
  127.     }
  128.  
  129.     .pds-table-wrapper tr td{
  130.         font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  131.         text-align: center;
  132.         line-height: $table-row-line-height;
  133.         //border: 1px solid $main-border-color;
  134.         font-size: $table-cells-font-size;
  135.     }
  136.  
  137.     .pds-table-row{
  138.         line-height: $box-height;
  139.         word-break: break-all;
  140.         font-size: $table-font-size;
  141.         &.table-row-small{
  142.             line-height: $box-height-small;
  143.             font-size: $table-font-small-size;
  144.         }
  145.         &.table-row-medium{
  146.             line-height: $box-height-medium;
  147.             font-size: $table-font-medium-size;
  148.         }
  149.     }
  150.  
  151.     .pds-table-row:nth-child(odd){
  152.         background-color: $table-row-odd;
  153.     }
  154.     .pds-table-row:nth-child(even){
  155.         background-color: $table-row-even;
  156.     }
  157.  
  158.     .pds-table-row:hover{
  159.         background-color: $table-row-hover;
  160.         cursor: pointer;
  161.     }
  162.  
  163.     .pds-table-row-active > td {
  164.         font-weight: bold;
  165.     }    
  166.  
  167.     //pagination
  168.     .pds-table-pagination-wrapper{
  169.         width: 100%;
  170.         height: 50px;
  171.         margin-top: 10px;        
  172.     }
  173.  
  174.     .pds-pagination-container{
  175.         float: right;
  176.         display: flex;
  177.     }
  178.  
  179.     .pds-pagination-state-box{
  180.         width: 40px;
  181.         height: 40px;
  182.         background-color: #cecece;
  183.         margin-top: 5px;
  184.         margin-bottom: 5px;
  185.         margin-left: 2px;
  186.         margin-right: 2px;
  187.         display: inline-block;
  188.         border-radius: 5px;
  189.     }
  190.  
  191.     .pds-pagination-state-box-label{
  192.         font-size: 12px;
  193.         padding-top: 10px;
  194.         padding-left: 16px;
  195.     }
  196. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement