An open API service indexing awesome lists of open source software.

https://github.com/runkids/vue-column-sortable

:arrows_clockwise: vue-column-sortable is an data sortable directive for vue.js.
https://github.com/runkids/vue-column-sortable

column-sorting orderby sort sortable sortable-helper table-sorting vue vue-directive

Last synced: 12 days ago
JSON representation

:arrows_clockwise: vue-column-sortable is an data sortable directive for vue.js.

Awesome Lists containing this project

README

          

# vue-column-sortable
[![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/) [![npm](https://img.shields.io/npm/v/vue-column-sortable.svg)](https://www.npmjs.com/package/vue-column-sortable)

vue-column-sortable is an data sortable directive for vue.js.

### Demo
[![Edit Vue Template](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/jvj47rxz33?module=%2Fsrc%2FApp.vue)

### Install

- In ES2015
```Bash
npm install vue-column-sortable --save
```
```JavaScript
//globally
import columnSortable from 'vue-column-sortable'
Vue.use(columnSortable)

//for a single instance
import columnSortable from 'vue-column-sortable'
new Vue({
directives: {columnSortable}
})
```

- Direct include

```html

```

### Usage

- Step 1
- Use v-column-sortable:{ data key } in HTML
```html


Name
Age
.
.


```
- Step 2
- copy method: orderBy

```javascript
new Vue({
el: '#app',
data: {
userArray: [
{ name: 'John', age: 20 },
{ name: 'Peter', age: 22 },
]
},
directives: {columnSortable},
methods:{
orderBy(sortFn) {
// sort your array data like this.userArray
this.userArray.sort(sortFn);
},
}
})
```
#### Options

###### showIcon
Default `true`
Show sort icon with `fortawesome` svg

```javascript
Vue.use(columnSortable, {
showIcon: false,
});
```

### Code Example

```html




#
Name
Date of Birth
Point
Country
City



{{ index+1 }}
{{ d.name }}
{{ d.birthday }}
{{ d.point }}
{{ d.address.country }}
{{ d.address.city }}



```
```javascript

import columnSortable from 'vue-column-sortable'

export default {
data() {
return {
dataArray: [
{
name: 'Jimmy Rutherford',
birthday: '1945-5-6',
point: 100,
address: {
country: 'United States of America',
city: 'South Ryann',
},
},
{
name: 'Camila Gutmann',
birthday: '1950-11-16',
point: 230,
address: {
country: 'Taiwan',
city: 'Lake Destinview',
},
},
],
};
},
methods: {
orderBy(fn) {
this.dataArray.sort(fn);
},
},
directives: {
columnSortable,
},
};

```

### License

MIT