Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit 494aef8

Browse files
author
Ken Berkeley
committed
[Support i18n] locale example see locales/zh-cn.js
1 parent f678add commit 494aef8

File tree

12 files changed

+77
-36
lines changed

12 files changed

+77
-36
lines changed

examples/src/Advanced/comps/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
Email: require('./td-Email'),
77
IP: require('./td-IP'),
88
Opt: require('./td-Opt'),
9+
FilterTh: require('./th-Filter')
910
// [Vue warn]: Do not use built-in or reserved HTML elements as component id: Filter
1011
// Filter: require('./th-Filter')
11-
FilterTh: require('./th-Filter')
1212
}

examples/src/Advanced/comps/th-Createtime.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export default {
3030
.-th-createtime-comp > select {
3131
display: inline-block;
3232
width: 80px;
33+
height: 26px;
3334
}
3435
</style>

examples/src/Advanced/index.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
</template>
1717
<script>
1818
import Vue from 'vue'
19-
import Datatable from '../../../'
2019
import mockData from '../_mockData'
21-
import comps from './comps/'
20+
import components from './comps/'
2221
2322
export default {
24-
name: 'FriendsTable', // `name` is required as a recursive component!
23+
components,
24+
name: 'FriendsTable', // `name` is required as a recursive component
2525
props: ['row'], // `props.row` from the parent FriendsTable (if exists)
26-
components: { Datatable, ...comps },
2726
data () {
2827
return {
2928
columns: [{
@@ -37,7 +36,7 @@ export default {
3736
}, {
3837
groupName: 'Sortable',
3938
columns: [
40-
{ title: 'User ID', field: 'uid', sort: true, visible: 'true', weight: 1 },
39+
{ title: 'UID', field: 'uid', label: 'User ID', sort: true, visible: 'true', weight: 1 },
4140
{ title: 'Age', field: 'age', sort: true, thClass: 'text-info', tdClass: 'text-success' },
4241
{ title: 'Create time', field: 'createTime', sort: true, colClass: 'w-240', thComp: 'CreatetimeTh', tdComp: 'CreatetimeTd' }
4342
]

examples/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
</ul>
4141
<div class="tab-content m-t-10">
4242
<div class="tab-pane" :class="{ active: showTab === 'basic' }">
43-
<basic />
43+
<basic v-if="showTab === 'basic'" />
4444
</div>
4545
<div class="tab-pane" :class="{ active: showTab === 'advanced' }">
46-
<advanced />
46+
<advanced v-if="showTab === 'advanced'" />
4747
</div>
4848
</div>
4949
</div>

examples/src/Basic/index.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
</div>
66
</template>
77
<script>
8-
import Datatable from '../../../'
98
import mockData from '../_mockData'
109
1110
export default {
12-
components: { Datatable },
1311
data: () => ({
1412
columns: [
1513
{ title: 'User ID', field: 'uid', sort: true },

examples/src/app.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
import Datatable from '../../'
4+
// import locale from '../../locales/zh-cn'
5+
6+
Vue.use(Datatable)
7+
// Vue.use(Datatable, { locale })
8+
9+
new Vue({
10+
el: '#app',
11+
render: h => h(App)
12+
})

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Datatable from './lib/'
2+
3+
export default {
4+
install (Vue, options = {}) {
5+
const { locale = {} } = options
6+
7+
// this might be the simplest i18n solution
8+
Vue.prototype.$i18n = srcTxt => locale[srcTxt] || srcTxt
9+
10+
Vue.component('Datatable', Datatable)
11+
}
12+
}

lib/HeaderSettings/index.vue

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template>
22
<div class="btn-group">
33
<button class="btn btn-default dropdown-toggle" ref="dropdownBtn">
4-
<i class="fa" :class="[usingBak && 'text-info', processingIcon || 'fa-cog']"></i>
4+
<i class="fa" :class="[usingBak && 'text-info', processingCls || 'fa-cog']"></i>
55
<span class="caret"></span>
66
</button>
77
<div class="dropdown-menu p-10 clearfix" :style="drpMenuStyle">
88
<div class="-col-group-container">
9-
<column-group v-for="group in colGroups" :key="group.groupName" ref="colGroups" :col-group="group" />
9+
<column-group v-for="(group, idx) in colGroups" :key="idx" ref="colGroups" :col-group="group" />
1010
</div>
1111
<div class="m-10 clearfix">
1212
<div class="btn-group btn-group-sm pull-right">
1313
<button class="btn btn-default" @click="apply()">
14-
Apply
14+
{{ $i18n('Apply') }}
1515
</button>
1616
<template v-if="supportBackup">
1717
<button data-toggle="dropdown" class="btn btn-default dropdown-toggle box-shadow-none">
@@ -21,21 +21,21 @@
2121
<li @click="apply(true)">
2222
<a href="javascript:;">
2323
<i class="fa fa-floppy-o"></i>&nbsp;
24-
Apply and backup settings to local
24+
{{ $i18n('Apply and backup settings to local') }}
2525
</a>
2626
</li>
2727
<li v-if="usingBak" @click="rmBackup()">
2828
<a href="javascript:;">
2929
<i class="fa fa-trash-o text-danger"></i>&nbsp;
30-
Clear local settings backup and restore
30+
{{ $i18n('Clear local settings backup and restore') }}
3131
</a>
3232
</li>
3333
</ul>
3434
</template>
3535
</div>
3636
</div>
37-
<small v-if="usingBak" class="pull-left text-muted">
38-
( Using local settings )
37+
<small v-if="usingBak" class="pull-left text-muted m-t--20">
38+
( {{ $i18n('Using local settings') }} )
3939
</small>
4040
</div>
4141
</div>
@@ -49,8 +49,8 @@ const stringify = JSON.stringify
4949
const rmFromLS = k => LS.removeItem(k)
5050
const saveToLS = (k, v) => LS.setItem(k, stringify(v))
5151
const getFromLS = k => { try { return parseStr(LS.getItem(k)) } catch (e) { rmFromLS(k) } }
52-
// hashCode http://stackoverflow.com/a/15710692/5172890
5352
const hash = s => '' + s.split('').reduce((a, b) => (a = (a << 5) - a + b.charCodeAt(0), a & a), 0)
53+
// the hash algorithm above refers to http://stackoverflow.com/a/15710692/5172890
5454
5555
export default {
5656
components: { ColumnGroup },
@@ -72,7 +72,7 @@ export default {
7272
return {
7373
origSettings,
7474
usingBak: false,
75-
processingIcon: '',
75+
processingCls: '',
7676
localKey: this.supportBackup && hash(origSettings) // key for local backup
7777
}
7878
},
@@ -86,7 +86,7 @@ export default {
8686
}
8787
},
8888
mounted () {
89-
// control dropdown manually, refers to http://jsfiddle.net/rj3k550m/3
89+
// control dropdown manually (refers to http://jsfiddle.net/rj3k550m/3)
9090
const $el = $(this.$el)
9191
$(this.$refs.dropdownBtn).on('click', this.toggle)
9292
$(document).on('click', e => {
@@ -116,26 +116,26 @@ export default {
116116
},
117117
showProcessing () {
118118
['fa-spinner fa-pulse', 'fa-check', ''].forEach((cls, idx) => {
119-
setTimeout(() => this.processingIcon = cls, idx * 1000)
119+
setTimeout(() => this.processingCls = cls, idx * 1000)
120120
})
121121
}
122122
}
123123
}
124124
</script>
125125
<style>
126-
.overflow-auto {
127-
overflow: auto;
126+
.-col-group-container {
127+
border-bottom: 1px solid #ddd;
128128
}
129129
.p-10 {
130130
padding: 10px 10px 0 10px;
131131
}
132132
.m-10 {
133133
margin: 10px;
134134
}
135+
.m-t--20 {
136+
margin-top: -20px;
137+
}
135138
.box-shadow-none {
136139
box-shadow: none !important;
137140
}
138-
.-col-group-container {
139-
border-bottom: 1px solid #ddd;
140-
}
141141
</style>

lib/LimitSelect.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<label>
3-
Show
4-
<select class="form-control input-sm inline-select" v-model="limit">
3+
{{ $i18n('show') }}
4+
<select class="form-control input-sm -limit-select" v-model="limit">
55
<option v-for="i in options" :value="i">{{ i }}</option>
66
</select>
7-
items per page
7+
{{ $i18n('items per page') }}
88
</label>
99
</template>
1010
<script>
@@ -27,7 +27,7 @@ export default {
2727
}
2828
</script>
2929
<style>
30-
.inline-select {
30+
.-limit-select {
3131
display: inline-block;
3232
width: 65px;
3333
}

lib/index.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,24 @@
7878
</td>
7979
<td v-else>
8080
<!-- show summary label if the first column field has no data -->
81-
<i v-if="!idx" class="text-muted">Summary</i>
81+
<i v-if="!idx" class="text-muted">
82+
{{ $i18n('Summary') }}
83+
</i>
8284
</td>
8385
</template>
8486
</tr>
8587
</template><!-- v-if="data.length" -->
8688
<tr v-else>
8789
<td :colspan="colspan" class="text-center text-muted">
88-
( No Data )
90+
( {{ $i18n('No Data') }} )
8991
</td>
9092
</tr>
9193
</tbody>
9294
</table>
9395
</div><!-- .table-responsive -->
9496
<div v-if="Pagination" class="row">
9597
<div class="col-sm-6 nowrap">
96-
<strong>Total {{ total }} ,</strong>
98+
<strong>{{ $i18n('Total') }} {{ total }} {{ $i18n(',') }}</strong>
9799
<limit-select :query="query" />
98100
</div>
99101
<div class="col-sm-6">
@@ -150,6 +152,7 @@ export default {
150152
)
151153
// sort by columns$[i].weight in descending order
152154
return _orderBy(columns$.map(col => ((col.weight = col.weight || 0), col)), 'weight', 'desc')
155+
153156
// the sort shown below is not stable
154157
// return columns$.map(col => ((col.weight = col.weight || 0), col)).sort((a, b) => b.weight - a.weight)
155158
},

0 commit comments

Comments
 (0)