Skip to content

Commit e9ae9d1

Browse files
author
syshex
committed
#14 - fixed - Added new properties to accomplish this
1 parent 20b4e06 commit e9ae9d1

File tree

3 files changed

+71
-24
lines changed

3 files changed

+71
-24
lines changed

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ <h1>Vue Bootstrap Table</h1>
3636
:show-column-picker="showPicker"
3737
:paginated="paginated"
3838
:multi-column-sortable="multiColumnSortable"
39+
:default-order-column="columnToSortBy"
40+
:default-order-direction=false
3941
:ajax="ajax"
4042
:row-click-handler=handleRowFunction
4143
:filter-case-sensitive=false

src/VueBootstrapTable.vue

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
</style>
182182
<script>
183183
184+
/* used for fixing IE problems*/
184185
import { polyfill } from 'es6-promise'; polyfill();
185186
import axios from 'axios';
186187
import qs from 'qs';
@@ -301,6 +302,22 @@
301302
required: false,
302303
default: 10,
303304
},
305+
/**
306+
* Setting default order column. Expected name of the column
307+
*/
308+
defaultOrderColumn: {
309+
type: String,
310+
required: false,
311+
default: null,
312+
},
313+
/**
314+
* Setting default order direction. Boolean: true = ASC , false = DESC
315+
*/
316+
defaultOrderDirection: {
317+
type: Boolean,
318+
required: false,
319+
default: true,
320+
},
304321
/**
305322
* If loading of table is to be done through ajax, then this object must be set
306323
*/
@@ -342,34 +359,59 @@
342359
loading: false,
343360
};
344361
},
362+
/**
363+
* Once mounted and ready to start
364+
*/
345365
mounted: function () {
346-
this.$nextTick(function () {
347-
this.loading= true;
348-
this.setSortOrders();
349-
var self = this;
350-
this.columns.forEach(function (column) {
351-
var obj = self.buildColumnObject(column);
352-
self.displayCols.push(obj);
353-
});
354-
if (this.ajax.enabled) {
355-
if (!this.ajax.delegate) {
356-
this.loading= true;
357-
this.fetchData(function (data) {
358-
self.rawValues = data.data;
359-
self.processFilter();
360-
});
361-
}else
362-
this.processFilter();
363-
}else {
364-
self.rawValues = self.values;
365-
this.processFilter();
366-
}
367-
})
366+
this.$nextTick(function () {
367+
this.loading = true;
368+
this.setSortOrders();
369+
var self = this;
370+
//
371+
if (this.defaultOrderColumn !== null) {
372+
console.log("setting order default");
373+
self.sortKey[0] = this.defaultOrderColumn;
374+
if (this.defaultOrderDirection)
375+
self.sortOrders[this.defaultOrderColumn] = "ASC";
376+
else
377+
self.sortOrders[this.defaultOrderColumn] = "DESC";
378+
}
379+
// Build columns
380+
this.columns.forEach(function (column) {
381+
var obj = self.buildColumnObject(column);
382+
self.displayCols.push(obj);
383+
});
384+
// Work the data
385+
if (this.ajax.enabled) {
386+
if (!this.ajax.delegate) {
387+
// If ajax but NOT delegate
388+
// Perform the fetch of data now and set the raw values
389+
this.loading = true;
390+
this.fetchData(function (data) {
391+
self.rawValues = data.data;
392+
});
393+
} else {
394+
// If ajax and also delegate
395+
// Simply call processFilter, which will take care of the fetching
396+
//this.processFilter();
397+
}
398+
} else {
399+
// Not ajax, therefore working with given elements
400+
// Pass the Prop values to rawValues data object.
401+
self.rawValues = self.values;
402+
}
403+
})
368404
},
405+
/**
406+
* On created register on CellDataModified event
407+
*/
369408
created: function () {
370409
var self = this ;
371410
this.$on('cellDataModifiedEvent', self.fireCellDataModifiedEvent);
372411
},
412+
/**
413+
* On destroy unregister the event
414+
*/
373415
beforeDestroy: function(){
374416
var self = this ;
375417
this.$off('cellDataModifiedEvent', self.fireCellDataModifiedEvent);
@@ -458,6 +500,9 @@
458500
},
459501
},
460502
methods: {
503+
/**
504+
* Used to fire off events when something happens to a cell
505+
*/
461506
fireCellDataModifiedEvent:function ( originalValue, newValue, columnTitle, entry) {
462507
this.$parent.$emit('cellDataModifiedEvent',originalValue, newValue, columnTitle, entry);
463508
},
@@ -512,7 +557,6 @@
512557
}
513558
},
514559
fetchData: function ( dataCallBackFunction ) {
515-
console.log("fetching data");
516560
var self = this;
517561
var ajaxParameters = {
518562
params: {}

src/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ new Vue({
2323
paginated: true,
2424
multiColumnSortable: true,
2525
handleRowFunction: handleRow,
26+
columnToSortBy:"name",
2627
ajax: {
2728
enabled: true,
2829
url: "http://172.16.213.1:9430/data/test",
2930
method: "POST",
30-
delegate: false,
31+
delegate: true,
3132
axiosConfig:{
3233
headers: {
3334
'Authorization': 'Bearer TESTTESTTESTTESTTEST'

0 commit comments

Comments
 (0)