Skip to content

Commit 2ed1d1f

Browse files
committed
Add sort event to columns
1 parent ddb933b commit 2ed1d1f

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
.DS_Store
2+
.idea
23
node_modules/
34
npm-debug.log*
45
yarn-debug.log*
56
yarn-error.log*
67
test/unit/coverage
78
test/e2e/reports
8-
selenium-debug.log
9+
selenium-debug.log

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@
9090
"lolex": "^1.5.2",
9191
"mocha": "^3.2.0",
9292
"nightwatch": "^0.9.12",
93+
"node-sass": "^4.5.3",
9394
"opn": "^4.0.2",
9495
"optimize-css-assets-webpack-plugin": "^1.3.0",
9596
"ora": "^1.2.0",
9697
"phantomjs-prebuilt": "^2.1.14",
9798
"rimraf": "^2.6.0",
99+
"sass-loader": "^6.0.6",
98100
"selenium-server": "^3.0.1",
99101
"semver": "^5.3.0",
100102
"shelljs": "^0.7.6",

src/components/ClientDatasource.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default {
1515
perpage: 10,
1616
selected: null, // row and Object selected on click event
1717
indexSelected: -1, // index row selected on click event
18+
sortOrder: 0,
1819
search: '' // word to search in the table
1920
}
2021
}
@@ -44,4 +45,4 @@ export default {
4445
.mr1 {
4546
margin-right: 5px;
4647
}
47-
</style>
48+
</style>

src/components/ServerDatasource.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export default {
127127
loading: false,
128128
selected: null, // row and Object selected on click event
129129
indexSelected: -1, // index row selected on click event
130+
sortOrder: 0, // sort order selected on click event
130131
search: '', // word to search in the table,
131132
pagination: {
132133
total: 0,
@@ -152,7 +153,7 @@ export default {
152153
},
153154
columnItems () {
154155
return this.columns.map((column, index) => {
155-
return <th>{ column.name }</th>
156+
return <th on-click={ (e) => this.sortColumn(e, column, index) }>{ column.name }</th>
156157
})
157158
},
158159
columnObjects () {
@@ -189,6 +190,7 @@ export default {
189190
fetchFromObject: DatasourceUtils.fetchFromObject,
190191
changePage: DatasourceUtils.changePage,
191192
selectRow: DatasourceUtils.selectRow,
193+
sortColumn: DatasourceUtils.sortColumn,
192194
dynamicClass (defaultClass, customClass) {
193195
return `${defaultClass} ${customClass}`
194196
},
@@ -259,9 +261,9 @@ export default {
259261
width: 100%;
260262
height: 100%;
261263
background: rgba(229, 229, 229, 0.5);
262-
264+
263265
.v-spinner {
264-
position: absolute;
266+
position: absolute;
265267
top: 50%;
266268
left: 50%;
267269
margin-left: -25px;

src/utils/DatasourceUtils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const sortDirections = ['DESC', 'ASC']
2+
13
export default {
24
/**
35
* Find the element value using Recursive Method and return the value rendered if it's defined
@@ -51,6 +53,13 @@ export default {
5153
}
5254
},
5355

56+
sortColumn (e, column, index) {
57+
e.preventDefault()
58+
const sortOrder = sortDirections[this.sortOrder]
59+
this.sortOrder = +!this.sortOrder
60+
this.$emit('sort', { column, sort: true, order: sortOrder })
61+
},
62+
5463
/**
5564
* Computed property: Building custom string information with translation
5665
* @returns {String}

0 commit comments

Comments
 (0)