11<script >
2- import axios from ' axios'
3- import _ from ' lodash'
42import DatasourceUtils from ' ../utils/DatasourceUtils'
53import Pagination from ' ./Pagination.vue'
64import { EventBus } from ' ../utils/EventBus'
@@ -20,7 +18,7 @@ export default {
2018 < / select>
2119 < / div>
2220 < div class = " form-group pull-right" >
23- < input class = " form-control mr1" type= " text" on- input= { (e ) => this .sync ( ' search ' , e . target . value ) } placeholder= {this .translation .placeholder_search } / >
21+ < input class = " form-control mr1" type= " text" on- input= { (e ) => this .searching (e ) } placeholder= {this .translation .placeholder_search } / >
2422 < / div>
2523 < div class = " clearfix" >< / div>
2624 < / div>
@@ -55,11 +53,11 @@ export default {
5553 },
5654 props: {
5755 /**
58- * Table source url
56+ * Table source data
5957 * @type {Array}
6058 */
6159 source: {
62- type: String ,
60+ type: Array ,
6361 required: true
6462 },
6563 /**
@@ -114,12 +112,10 @@ export default {
114112 },
115113 created () {
116114 EventBus .$on (' pagination-change' , this .changePage )
117- this .setData ()
118115 },
119116 data () {
120117 return {
121118 perpage: 10 ,
122- tableData: [],
123119 selected: null , // row and Object selected on click event
124120 indexSelected: - 1 , // index row selected on click event
125121 search: ' ' , // word to search in the table,
@@ -144,12 +140,12 @@ export default {
144140 })
145141 },
146142 columnObjects () {
147- if (this .tableData .length === 0 ) {
143+ if (this .source .length === 0 ) {
148144 return < tr class = " text-center" >
149145 < td colspan= { this .columns .length }> { this .translation .records_not_found }< / td>
150146 < / tr>
151147 } else {
152- return this .tableData .map ((row , index ) => {
148+ return this .source .map ((row , index ) => {
153149 let columns = this .columns .map ((column , index ) => {
154150 return < td domPropsInnerHTML= { this .fetchFromObject (row, column .key , column .render ) }>< / td>
155151 })
@@ -187,19 +183,7 @@ export default {
187183 this .selected = null
188184 this .indexSelected = - 1
189185 this .pagination .current_page = 1
190- this .setData ()
191- this .$emit (' searching' , this .search )
192- },
193- setData () {
194- axios .get (` ${ this .source } ?per_page=${ this .perpage } &page=${ this .pagination .current_page } &search=${ this .search } ` )
195- .then ((response ) => {
196- this .tableData = response .data .data
197- this .pagination = response .data .pagination
198- this .perpage = this .pagination .per_page
199- })
200- .catch ((error ) => {
201- console .warn (` [VueDatasource] ${ error} ` )
202- })
186+ this .$emit (' searching' , e .target .value )
203187 }
204188 },
205189 watch: {
@@ -211,16 +195,12 @@ export default {
211195 this .selected = null
212196 this .indexSelected = - 1
213197 this .pagination .current_page = 1
214- this .setData ()
215198 this .$emit (' change' , {perpage: this .perpage , page: 1 })
216199 },
217- tableData () {
200+ source () {
218201 this .selected = null
219202 this .indexSelected = - 1
220- },
221- search: _ .debounce (function () {
222- this .setData ()
223- }, 500 )
203+ }
224204 }
225205}
226206 </script >
0 commit comments