Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Nov 4, 2018
1 parent a524aa2 commit 38f1dc2
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,13 @@ actions: {
}
```

## Customizable table head (th) columns
Let say you have a column `description`, you can provide table head template for the description column like so:
```html
<template slot="HEAD_description">
<h1>desc</h1>
</template>
```


# MIT
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20048,7 +20048,7 @@ exports = module.exports = __webpack_require__(2)(true);


// module
exports.push([module.i, "\n.select-checkbox, .select-all-checkbox {\n cursor: pointer;\n}\n.dataTables_length {\n float: left;\n padding-right: 10px;\n}\n", "", {"version":3,"sources":["/Users/tomn/Desktop/work/niiknow/vue-datatables-net/src/src/VdtnetTable.vue"],"names":[],"mappings":";AA+OA;EACA,gBAAA;CACA;AACA;EACA,YAAA;EACA,oBAAA;CACA","file":"VdtnetTable.vue","sourcesContent":["<template>\n <div class=\"vdtnet-container\">\n <div class=\"container-fluid vdtnet-head\"><slot name=\"HEAD\" /></div>\n <div class=\"vtdnet-body\">\n <table\n v-once\n ref=\"table\"\n :class=\"className\"\n cellpadding=\"0\"\n >\n <thead>\n <tr>\n <th\n v-for=\"(field, i) in options.columns\"\n :key=\"i\"\n :class=\"field.className\"\n >\n <slot\n :name=\"`HEAD_${field.name}`\"\n :field=\"field\"\n :i=\"i\"\n >\n <div v-html=\"field.title\" />\n </slot>\n </th>\n </tr>\n </thead>\n </table>\n </div>\n <div class=\"container-fluid vdtnet-foot\"><slot name=\"FOOT\" /></div>\n </div>\n</template>\n\n<script>\nexport default {\n name: 'VdtnetTable',\n props: {\n // Set the table classes you wish to use, default with bootstrap4\n // but you can override with: themeforest, foundation, etc..\n className: {\n type: String,\n default: 'table table-striped table-bordered dt-responsive nowrap w-100'\n },\n // the options object: https://datatables.net/manual/options\n opts: {\n type: Object\n },\n /**\n * List all fields to be converted to opts columns\n *\n * @type {Object}\n */\n fields: {\n type: Object\n },\n /**\n * Pass in DataTables.Net loaded jQuery to resolve\n * any multiple loaded browser jQuery conflict\n *\n * @type {Object}\n */\n jquery: {\n type: Object\n },\n /**\n * True to enable multi-select checkboxes\n * Current implementation require datatables.net-select\n *\n * @type Boolean\n */\n selectable: {\n type: Boolean\n }\n },\n data() {\n // initialize defaults\n return {\n options: {\n/*eslint-disable */\n dom: \"<'row'<'col-sm-12 col-md-9'lB><'col-sm-12 col-md-3'f>>\" +\n \"<'row'<'col-sm-12'tr>>\" +\n \"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>\",\n/*eslint-enable */\n columns: [],\n language: {\n infoFiltered: ''\n },\n buttons: [] // remove any button defaults\n },\n dataTable: null\n }\n },\n computed: {\n jq() {\n return this.jquery || window.jQuery\n }\n },\n created() {\n const vm = this\n const jq = vm.jq\n\n // allow user to override default options\n if (vm.opts) {\n vm.options = jq.extend({}, vm.options, vm.opts)\n }\n\n // if fields are passed in, generate column definition\n // from our custom fields schema\n if (vm.fields) {\n const fields = vm.fields\n const cols = vm.options.columns\n\n for (let k in fields) {\n const field = fields[k]\n field.name = field.name || k\n\n // generate\n let col = {\n searchable: field.searchable,\n title: field.label || k,\n width: field.width,\n data: field.name,\n visible: field.visible,\n className: field.className\n }\n\n if (field.width) {\n col.width = field.width\n }\n\n if (field.hasOwnProperty('defaultContent')) {\n col.defaultContent = field.defaultContent\n }\n\n if (field.hasOwnProperty('sortable')) {\n col.orderable = field.sortable\n }\n\n if (field.render) {\n col.render = field.render\n }\n // console.log(col)\n\n cols.push(col)\n }\n }\n\n if (vm.selectable) {\n // expand column\n vm.options.columns = [{\n orderable: false,\n className: 'select-checkbox',\n data: null,\n defaultContent: '',\n title: '<input type=\"checkbox\" class=\"select-all-checkbox\">',\n targets: 0\n }].concat(vm.options.columns)\n\n // console.log(vm.options.columns)\n vm.options.select = jq.extend(\n vm.options.select || {},\n {\n style: 'os',\n selector: 'td:first-child'\n }\n )\n\n if (!vm.options.order) {\n vm.options.order = [[1, 'asc']]\n }\n }\n },\n mounted() {\n const vm = this\n const jq = vm.jq\n const $el = jq(vm.$refs.table)\n\n // console.log(vm.options.buttons)\n vm.dataTable = $el.DataTable(vm.options)\n\n if (vm.selectable) {\n $el.on('click', 'th input.select-all-checkbox', (e) => {\n if(jq(e.target).is(':checked')) {\n vm.dataTable.rows().select()\n } else {\n vm.dataTable.rows().deselect()\n }\n })\n\n vm.dataTable.on('select deselect', () => {\n if (vm.dataTable.rows({\n selected: true\n }).count() !== vm.dataTable.rows().count()) {\n jq('th.select-checkbox').removeClass('selected')\n } else {\n jq('th.select-checkbox').addClass('selected')\n }\n })\n }\n\n // wire up edit, delete, and/or action buttons\n $el.on('click', '[data-action]', (e) => {\n e.preventDefault()\n e.stopPropagation()\n const target = jq(e.target)\n let that = target\n let action = that.attr('data-action')\n while(!action) {\n // don't let it propagate outside of container\n if (that.hasClass('vdtnet-container')) {\n // no action, simply exit\n return\n }\n that = that.parent()\n action = that.attr('data-action')\n }\n\n // only emit if there is action\n if (action) {\n // detect if row action\n let tr = that.closest('tr')\n if (tr) {\n if (tr.hasClass('child')) {\n tr = tr.prev()\n }\n const row = vm.dataTable.row(tr)\n const data = row.data()\n vm.$emit(action, {data, row, that})\n } else {\n // not a row click, must be other kind of action\n // such as bulk, csv, pdf, etc...\n vm.$emit(action, {target})\n }\n }\n })\n }\n}\n</script>\n<style>\n.select-checkbox, .select-all-checkbox {\n cursor: pointer;\n}\n.dataTables_length {\n float: left;\n padding-right: 10px;\n}\n</style>\n"],"sourceRoot":""}]);
exports.push([module.i, "\n.select-checkbox, .select-all-checkbox {\n cursor: pointer;\n}\n.dataTables_length {\n float: left;\n padding-right: 10px;\n}\n", "", {"version":3,"sources":["/Users/tomn/Desktop/work/niiknow/vue-datatables-net/src/src/VdtnetTable.vue"],"names":[],"mappings":";AAkPA;EACA,gBAAA;CACA;AACA;EACA,YAAA;EACA,oBAAA;CACA","file":"VdtnetTable.vue","sourcesContent":["<template>\n <div class=\"vdtnet-container\">\n <div class=\"container-fluid vdtnet-head\"><slot name=\"HEAD\" /></div>\n <div class=\"vtdnet-body\">\n <table\n v-once\n ref=\"table\"\n :class=\"className\"\n cellpadding=\"0\"\n >\n <thead>\n <tr>\n <th\n v-for=\"(field, i) in options.columns\"\n :key=\"i\"\n :class=\"field.className\"\n >\n <slot\n :name=\"`HEAD_${field.name}`\"\n :field=\"field\"\n :i=\"i\"\n >\n <div v-html=\"field.title\" />\n </slot>\n </th>\n </tr>\n </thead>\n </table>\n </div>\n <div class=\"container-fluid vdtnet-foot\"><slot name=\"FOOT\" /></div>\n </div>\n</template>\n\n<script>\nexport default {\n name: 'VdtnetTable',\n props: {\n // Set the table classes you wish to use, default with bootstrap4\n // but you can override with: themeforest, foundation, etc..\n className: {\n type: String,\n default: 'table table-striped table-bordered dt-responsive nowrap w-100'\n },\n // the options object: https://datatables.net/manual/options\n opts: {\n type: Object\n },\n /**\n * List all fields to be converted to opts columns\n *\n * @type {Object}\n */\n fields: {\n type: Object\n },\n /**\n * Pass in DataTables.Net loaded jQuery to resolve\n * any multiple loaded browser jQuery conflict\n *\n * @type {Object}\n */\n jquery: {\n type: Object\n },\n /**\n * True to enable multi-select checkboxes\n * Current implementation require datatables.net-select\n *\n * @type Boolean\n */\n selectable: {\n type: Boolean\n }\n },\n data() {\n // initialize defaults\n return {\n options: {\n/*eslint-disable */\n dom: \"<'row'<'col-sm-12 col-md-9'lB><'col-sm-12 col-md-3'f>>\" +\n \"<'row'<'col-sm-12'tr>>\" +\n \"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>\",\n/*eslint-enable */\n columns: [],\n language: {\n infoFiltered: ''\n },\n buttons: [] // remove any button defaults\n },\n dataTable: null\n }\n },\n computed: {\n jq() {\n return this.jquery || window.jQuery\n }\n },\n created() {\n const vm = this\n const jq = vm.jq\n\n // allow user to override default options\n if (vm.opts) {\n vm.options = jq.extend({}, vm.options, vm.opts)\n }\n\n // if fields are passed in, generate column definition\n // from our custom fields schema\n if (vm.fields) {\n const fields = vm.fields\n const cols = vm.options.columns\n\n for (let k in fields) {\n const field = fields[k]\n field.name = field.name || k\n\n // generate\n let col = {\n searchable: field.searchable,\n title: field.label || k,\n width: field.width,\n data: field.name,\n visible: field.visible,\n className: field.className\n }\n\n if (field.width) {\n col.width = field.width\n }\n\n if (field.hasOwnProperty('defaultContent')) {\n col.defaultContent = field.defaultContent\n }\n\n if (field.hasOwnProperty('sortable')) {\n col.orderable = field.sortable\n }\n\n if (field.render) {\n col.render = field.render\n }\n // console.log(col)\n\n cols.push(col)\n }\n }\n\n if (vm.selectable) {\n // expand column\n vm.options.columns = [{\n orderable: false,\n className: 'select-checkbox',\n data: null,\n defaultContent: '',\n title: '<input type=\"checkbox\" class=\"select-all-checkbox\">',\n targets: 0\n }].concat(vm.options.columns)\n\n // console.log(vm.options.columns)\n vm.options.select = jq.extend(\n vm.options.select || {},\n {\n style: 'os',\n selector: 'td:first-child'\n }\n )\n\n if (!vm.options.order) {\n vm.options.order = [[1, 'asc']]\n }\n }\n },\n mounted() {\n const vm = this\n const jq = vm.jq\n const $el = jq(vm.$refs.table)\n\n // console.log(vm.options.buttons)\n vm.dataTable = $el.DataTable(vm.options)\n\n if (vm.selectable) {\n $el.on('click', 'th input.select-all-checkbox', (e) => {\n if(jq(e.target).is(':checked')) {\n vm.dataTable.rows().select()\n } else {\n vm.dataTable.rows().deselect()\n }\n })\n\n vm.dataTable.on('select deselect', () => {\n const $input = $el.find('th input.select-all-checkbox')\n if (vm.dataTable.rows({\n selected: true\n }).count() !== vm.dataTable.rows().count()) {\n jq('th.select-checkbox').removeClass('selected')\n $input.attr('checked', false)\n } else {\n jq('th.select-checkbox').addClass('selected')\n $input.attr('checked', true)\n }\n })\n }\n\n // wire up edit, delete, and/or action buttons\n $el.on('click', '[data-action]', (e) => {\n e.preventDefault()\n e.stopPropagation()\n const target = jq(e.target)\n let that = target\n let action = that.attr('data-action')\n while(!action) {\n // don't let it propagate outside of container\n if (that.hasClass('vdtnet-container')) {\n // no action, simply exit\n return\n }\n that = that.parent()\n action = that.attr('data-action')\n }\n\n // only emit if there is action\n if (action) {\n // detect if row action\n let tr = that.closest('tr')\n if (tr) {\n if (tr.hasClass('child')) {\n tr = tr.prev()\n }\n const row = vm.dataTable.row(tr)\n const data = row.data()\n vm.$emit(action, {data, row, that})\n } else {\n // not a row click, must be other kind of action\n // such as bulk, csv, pdf, etc...\n vm.$emit(action, {target})\n }\n }\n })\n }\n}\n</script>\n<style>\n.select-checkbox, .select-all-checkbox {\n cursor: pointer;\n}\n.dataTables_length {\n float: left;\n padding-right: 10px;\n}\n</style>\n"],"sourceRoot":""}]);

// exports

Expand Down Expand Up @@ -20245,12 +20245,15 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
});

vm.dataTable.on('select deselect', function () {
var $input = $el.find('th input.select-all-checkbox');
if (vm.dataTable.rows({
selected: true
}).count() !== vm.dataTable.rows().count()) {
jq('th.select-checkbox').removeClass('selected');
$input.attr('checked', false);
} else {
jq('th.select-checkbox').addClass('selected');
$input.attr('checked', true);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 38f1dc2

Please sign in to comment.