VueTable.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="table">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item><i class="el-icon-menu"></i> 表格</el-breadcrumb-item>
  6. <el-breadcrumb-item>Vue表格组件</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <div class="plugins-tips">
  10. vue-datasource:一个用于动态创建表格的vue.js服务端组件。
  11. 访问地址:<a href="https://github.com/coderdiaz/vue-datasource" target="_blank">vue-datasource</a>
  12. </div>
  13. <datasource language="en" :table-data="getData" :columns="columns" :pagination="information.pagination"
  14. :actions="actions"
  15. v-on:change="changePage"
  16. v-on:searching="onSearch"></datasource>
  17. </div>
  18. </template>
  19. <script>
  20. import Datasource from 'vue-datasource';
  21. export default {
  22. data: function(){
  23. return {
  24. information: {
  25. pagination: {
  26. total: 25, // Number of total rows (default 0)
  27. per_page: 15, // Number of rows to show (default 15)
  28. current_page: 1, // Actual page
  29. last_page: 2, // Last page
  30. from: 1, // Beginning of visible rows
  31. to: 15 // End of visible rows
  32. },
  33. data: [{
  34. "id": 1,
  35. "name": "Jaylen Schmidt",
  36. "email": "aheaney@example.org",
  37. "city": "Conroyburgh",
  38. "company": "Kunde, Gerhold and Runte"
  39. },
  40. {
  41. "id": 2,
  42. "name": "Ms. Desiree Franecki III",
  43. "email": "pweissnat@example.net",
  44. "city": "New Mathew",
  45. "company": "Davis Ltd"
  46. },
  47. {
  48. "id": 3,
  49. "name": "Clyde Corwin",
  50. "email": "rolfson.lexus@example.com",
  51. "city": "East Ron",
  52. "company": "Zieme and Sons"
  53. }]
  54. },
  55. columns: [
  56. {
  57. name: 'Id',
  58. key: 'id',
  59. },
  60. {
  61. name: 'Name',
  62. key: 'name',
  63. },
  64. {
  65. name: 'email',
  66. key: 'email',
  67. },
  68. {
  69. name: 'company',
  70. key: 'company',
  71. }
  72. ],
  73. actions: [
  74. {
  75. text: 'Click me', // Button label
  76. icon: 'glyphicon glyphicon-check', // Button icon
  77. class: 'btn-primary', // Button class (background color)
  78. event(e, row) { // Event handler callback. Gets event instace and selected row
  79. console.log('Click row: ', row); // If no row is selected, row will be NULL
  80. }
  81. }
  82. ],
  83. query:''
  84. }
  85. },
  86. components: {
  87. Datasource
  88. },
  89. methods: {
  90. changePage(values) {
  91. this.information.pagination.per_page = values.perpage;
  92. this.information.data = this.information.data;
  93. },
  94. onSearch(searchQuery) {
  95. this.query = searchQuery;
  96. }
  97. },
  98. computed:{
  99. getData(){
  100. const self = this;
  101. return self.information.data.filter(function (d) {
  102. if(d.name.indexOf(self.query) > -1){
  103. return d;
  104. }
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style src="../../../static/css/datasource.css"></style>