Skip to content

Commit 70ca7fa

Browse files
committed
allow for setting default order by schema
1 parent 1c66f0a commit 70ca7fa

File tree

8 files changed

+34
-9
lines changed

8 files changed

+34
-9
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ fields: {
196196
- `defaultContent` provide default html when no data available
197197
- `render` custom cell rendering function https://datatables.net/reference/option/columns.render
198198
- `template` simple vue template for the field. See example App.
199+
- `defaultOrder` null, asc/desc - the default/initial sort order
199200

200201
> It is important to understand why one should use `fields` and not `opts.columns`. Though, `fields` is optional, you can simply pass `opts.columns` definition if you do not wish to use `fields`.
201202

dist/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -16369,7 +16369,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
1636916369
created: function created() {
1637016370
var vm = this;
1637116371
var jq = vm.jq;
16372+
var orders = [];
16373+
1637216374
var sort = 0;
16375+
var icol = 0;
1637316376

1637416377
// allow user to override default options
1637516378
if (vm.opts) {
@@ -16418,9 +16421,18 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
1641816421
// console.log(col)
1641916422

1642016423
cols.push(col);
16424+
16425+
if (col.defaultOrder) {
16426+
orders.push([icol, col.defaultOrder]);
16427+
}
16428+
16429+
icol++;
1642116430
}
1642216431
}
1642316432

16433+
// apply orders calculated from above
16434+
vm.options.order = vm.options.order || orders;
16435+
1642416436
if (vm.selectCheckbox) {
1642516437
// expand column
1642616438
var _col = {

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/mix-manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"/index.js": "/index.js?id=42c742b0948268c308ac",
3-
"/index.js.map": "/index.js.map?id=9ac43f02d49480ed2578"
2+
"/index.js": "/index.js?id=7ee15f6b617974705b45",
3+
"/index.js.map": "/index.js.map?id=226097290267f14622d6"
44
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-datatables-net",
33
"description": "Vue jQuery DataTables.net wrapper component",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"author": "[email protected]",
66
"license": "MIT",
77
"main": "lib/index.js",

src/VdtnetTable.vue

+15-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ export default {
135135
}
136136
},
137137
created() {
138-
const vm = this
139-
const jq = vm.jq
140-
let sort = 0
138+
const vm = this
139+
const jq = vm.jq
140+
const orders = []
141+
142+
let sort = 0
143+
let icol = 0
141144
142145
// allow user to override default options
143146
if (vm.opts) {
@@ -186,9 +189,18 @@ export default {
186189
// console.log(col)
187190
188191
cols.push(col)
192+
193+
if (col.defaultOrder) {
194+
orders.push([icol, col.defaultOrder])
195+
}
196+
197+
icol++
189198
}
190199
}
191200
201+
// apply orders calculated from above
202+
vm.options.order = vm.options.order || orders
203+
192204
if (vm.selectCheckbox) {
193205
// expand column
194206
const col = {

0 commit comments

Comments
 (0)