Skip to content

Commit

Permalink
Native column templating, sort-of
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Sep 3, 2019
1 parent 043e7ac commit a92f268
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ If you're like us, you want to write as little code as possible; as in, applicat
3. Wrap individual action events you want to expose, or simply wrap with v-on="$listeners" to pipe all events from this component to your component.
## Roadmap
- [ ] Native column templating. It may be possible to natively template and render column with all @events wired up. Still need to look into this.
- [ ] Inline editable. This will depend on native column templating capability.
- [x] Native column templating.
- [ ] Inline editable.
- [ ] This library is inspired by both [Bootstrap-Vue](https://bootstrap-vue.js.org/) and [jQuery DataTables](https://datatables.net/). Look into creating jQuery DataTables server-side items provider for [Bootstrap-Vue Table](https://bootstrap-vue.js.org/docs/components/table#field-definition-reference) component. Since jQuery Datatables dependencies does not support server-side rendering (SSR), Bootstrap-Vue Table will likely be the answer.
## License
Expand Down
13 changes: 7 additions & 6 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ var myUniqueId = 1;
}

if (field.template) {
field.render = vm.compileTemplate(field.template);
field.render = vm.compileTemplate(field);
}

if (field.render) {
Expand Down Expand Up @@ -810,7 +810,7 @@ var myUniqueId = 1;
var renderFunc = vm.details.render; // must be string template

if (vm.details.template) {
renderFunc = vm.compileTemplate(vm.details.template);
renderFunc = vm.compileTemplate(vm.details);
} else if (renderFunc) {
renderFunc = function renderFunc() {
return vm.details.render.apply(vm, _arguments2);
Expand Down Expand Up @@ -864,13 +864,13 @@ var myUniqueId = 1;
/**
* Vue.compile a template string and return the compiled function
*
* @param {String} template the string template
* @param {Object} object with template property
* @return {Function} the compiled template function
*/
compileTemplate: function compileTemplate(template) {
compileTemplate: function compileTemplate(field) {
var vm = this;
var jq = vm.jq;
var res = Vue.compile("<div>".concat(template, "</div>"));
var res = Vue.compile("<div>".concat(field.template, "</div>"));

var renderFunc = function renderFunc(data, type, row, meta) {
var comp = new Vue({
Expand All @@ -879,7 +879,8 @@ var myUniqueId = 1;
type: type,
row: row,
meta: meta,
vdtnet: vm
vdtnet: vm,
def: field
},
render: res.render,
staticRenderFns: res.staticRenderFns
Expand Down
2 changes: 1 addition & 1 deletion example/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/index.js": "/index.js?id=3c7a4dc674e4f56d67e5",
"/index.js.map": "/index.js.map?id=56078c7b2ad40ab63ee5"
"/index.js": "/index.js?id=ba6728142b858139db55",
"/index.js.map": "/index.js.map?id=f10a7aab7fbc789bf4c0"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-datatables-net",
"description": "Vue jQuery DataTables.net wrapper component",
"version": "1.2.0",
"version": "1.2.1",
"author": "[email protected]",
"license": "MIT",
"main": "lib/index.js",
Expand Down
21 changes: 11 additions & 10 deletions src/VdtnetTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default {
}
if (field.template) {
field.render = vm.compileTemplate(field.template)
field.render = vm.compileTemplate(field)
}
if (field.render) {
Expand Down Expand Up @@ -392,7 +392,7 @@ export default {
// must be string template
if (vm.details.template) {
renderFunc = vm.compileTemplate(vm.details.template)
renderFunc = vm.compileTemplate(vm.details)
} else if (renderFunc) {
renderFunc = () => {
return vm.details.render.apply(vm, arguments)
Expand Down Expand Up @@ -444,21 +444,22 @@ export default {
/**
* Vue.compile a template string and return the compiled function
*
* @param {String} template the string template
* @param {Object} object with template property
* @return {Function} the compiled template function
*/
compileTemplate(template) {
compileTemplate(field) {
const vm = this
const jq = vm.jq
const res = Vue.compile(`<div>${template}</div>`)
const res = Vue.compile(`<div>${field.template}</div>`)
const renderFunc = (data, type, row, meta) => {
const comp = new Vue({
data: {
data: data,
type: type,
row: row,
meta: meta,
vdtnet: vm
data: data,
type: type,
row: row,
meta: meta,
vdtnet: vm,
def: field
},
render: res.render,
staticRenderFns: res.staticRenderFns
Expand Down

0 comments on commit a92f268

Please sign in to comment.