diff --git a/example/index.js b/example/index.js index 13aae37..26aa180 100644 --- a/example/index.js +++ b/example/index.js @@ -563,7 +563,8 @@ var myUniqueId = 1; buttons: [] // remove any button defaults }, - dataTable: null + dataTable: null, + vdtnet: this }; }, computed: { diff --git a/example/index.js.map b/example/index.js.map index a08a28d..50881a2 100644 --- a/example/index.js.map +++ b/example/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["webpack://VdtnetTable/webpack/universalModuleDefinition","webpack://VdtnetTable/webpack/bootstrap","webpack://VdtnetTable/./example/app.js","webpack://VdtnetTable/./example/app.vue","webpack://VdtnetTable/./example/app.vue?6ea0","webpack://VdtnetTable/./example/app.vue?5b50","webpack://VdtnetTable/./example/app.vue?338d","webpack://VdtnetTable/./src/VdtnetTable.vue?fc4d","webpack://VdtnetTable/./node_modules/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css","webpack://VdtnetTable/./node_modules/datatables.net-select-bs4/css/select.bootstrap4.min.css","webpack://VdtnetTable/./src/VdtnetTable.vue?da42","webpack://VdtnetTable/./node_modules/css-loader/dist/runtime/api.js","webpack://VdtnetTable/./node_modules/datatables.net-bs4/js/dataTables.bootstrap4.js","webpack://VdtnetTable/./node_modules/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css?5cfe","webpack://VdtnetTable/./node_modules/datatables.net-buttons-bs4/js/buttons.bootstrap4.js","webpack://VdtnetTable/./node_modules/datatables.net-buttons/js/buttons.html5.js","webpack://VdtnetTable/./node_modules/datatables.net-buttons/js/buttons.print.js","webpack://VdtnetTable/./node_modules/datatables.net-buttons/js/dataTables.buttons.js","webpack://VdtnetTable/./node_modules/datatables.net-select-bs4/css/select.bootstrap4.min.css?2d3e","webpack://VdtnetTable/./node_modules/datatables.net-select-bs4/js/select.bootstrap4.js","webpack://VdtnetTable/./node_modules/datatables.net-select/js/dataTables.select.js","webpack://VdtnetTable/./node_modules/datatables.net/js/jquery.dataTables.js","webpack://VdtnetTable/./src/VdtnetTable.vue?ff82","webpack://VdtnetTable/./node_modules/style-loader/lib/addStyles.js","webpack://VdtnetTable/./node_modules/style-loader/lib/urls.js","webpack://VdtnetTable/./example/app.vue?ddf7","webpack://VdtnetTable/./src/VdtnetTable.vue?13e7","webpack://VdtnetTable/./node_modules/vue-loader/lib/runtime/componentNormalizer.js","webpack://VdtnetTable/./src/VdtnetTable.vue","webpack://VdtnetTable/./src/VdtnetTable.vue?55c3","webpack://VdtnetTable/./src/VdtnetTable.vue?7176","webpack://VdtnetTable/./src/VdtnetTable.vue?3690","webpack://VdtnetTable/./src/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"jQuery\"), require(\"Vue\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"VdtnetTable\", [\"jQuery\", \"Vue\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VdtnetTable\"] = factory(require(\"jQuery\"), require(\"Vue\"));\n\telse\n\t\troot[\"VdtnetTable\"] = factory(root[\"jQuery\"], root[\"Vue\"]);\n})(window, function(__WEBPACK_EXTERNAL_MODULE_jquery__, __WEBPACK_EXTERNAL_MODULE_vue__) {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","import Vue from 'vue';\nimport App from './app.vue';\nnew Vue({\n el: '#app',\n render: function render(h) {\n return h(App);\n }\n});","import { render, staticRenderFns } from \"./app.vue?vue&type=template&id=480ac1de&scoped=true&\"\nimport script from \"./app.vue?vue&type=script&lang=js&\"\nexport * from \"./app.vue?vue&type=script&lang=js&\"\n\n\n/* normalize component */\nimport normalizer from \"!../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n \"480ac1de\",\n null\n \n)\n\n/* hot reload */\nif (module.hot) {\n var api = require(\"/Users/tomnoogen/Desktop/work/niiknow/vue-datatables-net/node_modules/vue-hot-reload-api/dist/index.js\")\n api.install(require('vue'))\n if (api.compatible) {\n module.hot.accept()\n if (!api.isRecorded('480ac1de')) {\n api.createRecord('480ac1de', component.options)\n } else {\n api.reload('480ac1de', component.options)\n }\n module.hot.accept(\"./app.vue?vue&type=template&id=480ac1de&scoped=true&\", function () {\n api.rerender('480ac1de', {\n render: render,\n staticRenderFns: staticRenderFns\n })\n })\n }\n}\ncomponent.options.__file = \"example/app.vue\"\nexport default component.exports","import mod from \"-!../node_modules/babel-loader/lib/index.js??ref--4-0!../node_modules/vue-loader/lib/index.js??vue-loader-options!./app.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../node_modules/babel-loader/lib/index.js??ref--4-0!../node_modules/vue-loader/lib/index.js??vue-loader-options!./app.vue?vue&type=script&lang=js&\"","export * from \"-!../node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../node_modules/vue-loader/lib/index.js??vue-loader-options!./app.vue?vue&type=template&id=480ac1de&scoped=true&\"","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n// this demonstrate with buttons and responsive master/details row\nimport VdtnetTable from '../src';\nimport 'datatables.net-bs4'; // import buttons and plugins\n\nimport 'datatables.net-buttons/js/dataTables.buttons.js';\nimport 'datatables.net-buttons/js/buttons.html5.js';\nimport 'datatables.net-buttons/js/buttons.print.js'; // import the rest\n\nimport 'datatables.net-buttons-bs4';\nimport 'datatables.net-select-bs4';\nimport 'datatables.net-select-bs4/css/select.bootstrap4.min.css';\nimport 'datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css';\nexport default {\n name: 'App',\n components: {\n VdtnetTable: VdtnetTable\n },\n data: function data() {\n var vm = this;\n return {\n options: {\n ajax: {\n url: 'https://jsonplaceholder.typicode.com/users',\n dataSrc: function dataSrc(json) {\n return json;\n }\n },\n buttons: ['copy', 'csv', 'print'],\n\n /*eslint-disable */\n dom: \"Btr<'row vdtnet-footer'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'pl>>\",\n\n /*eslint-enable */\n responsive: false,\n processing: true,\n searching: true,\n searchDelay: 1500,\n destroy: true,\n ordering: true,\n lengthChange: true,\n serverSide: true,\n fixedHeader: true,\n saveState: true\n },\n fields: {\n id: {\n label: 'ID',\n sortable: true\n },\n actions: {\n isLocal: true,\n label: 'Actions',\n defaultContent: ' Edit' + ' Delete'\n },\n name: {\n label: 'Name',\n sortable: true,\n searchable: true,\n defaultOrder: 'desc'\n },\n username: {\n label: 'Username',\n sortable: false,\n searchable: true\n },\n email: {\n label: 'Email'\n },\n address: {\n label: 'Address',\n template: '{{ data.street }}, {{ data.suite }}, {{ data.city }} {{ data.zipcode }}'\n },\n phone: {\n label: 'Phone'\n },\n website: {\n label: 'Website',\n render: function render(data) {\n return \"https://\".concat(data);\n }\n }\n },\n quickSearch: '',\n details: {\n template: 'I\\'m a child for {{ data.id }} yall'\n }\n };\n },\n methods: {\n doLoadTable: function doLoadTable(cb) {\n $.getJSON('https://jsonplaceholder.typicode.com/users', function (data) {\n cb(data);\n });\n },\n doAlertEdit: function doAlertEdit(data) {\n window.alert(\"row edit click for item ID: \".concat(data.id));\n },\n doAlertDelete: function doAlertDelete(data, row, tr, target) {\n window.alert(\"deleting item ID: \".concat(data.id)); // row.remove() doesn't work when serverside is enabled\n // so we fake it with dom remove\n\n tr.remove();\n var table = this.$refs.table;\n setTimeout(function () {\n // simulate extra long running ajax\n table.reload();\n }, 1500);\n },\n doAfterReload: function doAfterReload(data, table) {\n window.alert('data reloaded');\n },\n doCreating: function doCreating(comp, el) {\n console.log('creating');\n },\n doCreated: function doCreated(comp) {\n console.log('created');\n },\n doSearch: function doSearch() {\n this.$refs.table.search(this.quickSearch);\n },\n doExport: function doExport(type) {\n var parms = this.$refs.table.getServerParams();\n parms[\"export\"] = type;\n window.alert('GET /api/v1/export?' + jQuery.param(parms));\n }\n }\n};","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\nvar myUniqueId = 1;\nexport default {\n name: 'VdtnetTable',\n props: {\n /**\n * The table id\n *\n * @type String\n */\n id: {\n type: String,\n \"default\": null\n },\n\n /**\n * Set the container classes.\n *\n * @type String\n */\n containerClassName: {\n type: String,\n \"default\": 'table-responsive d-print-inline'\n },\n\n /**\n * Set the table classes you wish to use, default with bootstrap4\n * but you can override with: themeforest, foundation, etc..\n *\n * @type String\n */\n className: {\n type: String,\n \"default\": 'table table-striped table-bordered nowrap w-100'\n },\n\n /**\n * the options object: https://datatables.net/manual/options\n *\n * @type Object\n */\n opts: {\n type: Object\n },\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 /**\n * Pass in DataTables.Net jQuery to resolve any conflict from\n * multiple jQuery loaded in the browser\n *\n * @type Object\n */\n jquery: {\n type: Object\n },\n\n /**\n * The select-checkbox column index (start at 1)\n * Current implementation require datatables.net-select\n *\n * @type Number\n */\n selectCheckbox: {\n type: Number\n },\n\n /**\n * Provide custom local data loading. Warning: this option has not been\n * thoroughly tested. Please use ajax and serverSide instead.\n *\n * @type Function\n */\n dataLoader: {\n type: Function\n },\n\n /**\n * true to hide the footer of the table\n *\n * @type Boolean\n */\n hideFooter: {\n type: Boolean\n },\n\n /**\n * The details column configuration of master/details.\n *\n * @type {Object}\n */\n details: {\n type: Object\n }\n },\n data: function data() {\n // initialize defaults\n return {\n tableId: null,\n options: {\n /*eslint-disable */\n dom: \"tr<'row vdtnet-footer'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'pl>>\",\n\n /*eslint-enable */\n columns: [],\n language: {\n infoFiltered: ''\n },\n lengthMenu: [[15, 100, 500, 1000, -1], [15, 100, 500, 1000, 'All']],\n pageLength: 15,\n buttons: [] // remove any button defaults\n\n },\n dataTable: null\n };\n },\n computed: {\n jq: function jq() {\n return this.jquery || window.jQuery;\n },\n classes: function classes() {\n var that = this;\n var classes = \"\".concat(that.containerClassName, \" vdtnet-container\");\n\n if (this.hideFooter) {\n classes += ' hide-footer';\n }\n\n return classes;\n }\n },\n created: function created() {\n var _arguments = arguments;\n var vm = this;\n var jq = vm.jq;\n var orders = [];\n var startCol = 0;\n var icol = 0;\n vm.tableId = vm.id || \"vdtnetable\".concat(myUniqueId++); // allow user to override default options\n\n if (vm.opts) {\n vm.options = jq.extend({}, vm.options, vm.opts);\n } // if fields are passed in, generate column definition\n // from our custom fields schema\n\n\n if (vm.fields) {\n var fields = vm.fields;\n var cols = vm.options.columns;\n\n for (var k in fields) {\n var field = fields[k];\n field.name = field.name || k; // disable search and sort for local field\n\n if (field.isLocal) {\n field.searchable = false;\n field.sortable = false;\n } // generate\n\n\n var col = {\n title: field.label || field.name,\n width: field.width,\n data: field.data || field.name,\n name: field.name,\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.hasOwnProperty('visible')) {\n col.visible = field.visible;\n }\n\n if (field.hasOwnProperty('searchable')) {\n col.searchable = field.searchable;\n }\n\n if (field.template) {\n field.render = vm.compileTemplate(field.template);\n }\n\n if (field.render) {\n if (!field.render.templated) {\n (function () {\n var myRender = field.render;\n\n field.render = function () {\n return myRender.apply(vm, _arguments);\n };\n })();\n }\n\n col.render = field.render;\n } // console.log(col)\n\n\n cols.push(col);\n\n if (field.defaultOrder) {\n orders.push([icol, field.defaultOrder]);\n }\n\n icol++;\n }\n } // apply orders calculated from above\n\n\n vm.options.order = vm.options.order || orders;\n\n if (vm.selectCheckbox) {\n vm.selectCheckbox = vm.selectCheckbox || 1; // create checkbox column\n\n var _col = {\n orderable: false,\n searchable: false,\n name: '_select_checkbox',\n className: 'select-checkbox d-print-none',\n data: null,\n defaultContent: '',\n title: ''\n };\n vm.options.columns.splice(vm.selectCheckbox - 1, 0, _col); // console.log(vm.options.columns)\n\n vm.options.select = jq.extend(vm.options.select || {}, {\n style: 'os',\n selector: 'td.select-checkbox'\n });\n\n if (vm.selectCheckbox === 1) {\n startCol++;\n }\n } // handle master details\n\n\n if (vm.details) {\n vm.details.index = vm.details.index || 1; // create details column\n\n var _col2 = {\n orderable: false,\n searchable: false,\n name: '_details_control',\n className: 'details-control d-print-none',\n data: null,\n defaultContent: vm.details.icons || '+-'\n };\n vm.options.columns.splice(vm.details.index - 1, 0, _col2);\n\n if (vm.details.index === 1) {\n startCol++;\n }\n }\n\n if (startCol > 0) {\n if (vm.options.order) {\n vm.options.order.forEach(function (v) {\n v[0] += startCol;\n });\n } else {\n vm.options.order = [[startCol, 'asc']];\n }\n } // handle local data loader\n\n\n if (vm.dataLoader) {\n delete vm.options.ajax;\n vm.options.serverSide = false;\n }\n },\n mounted: function mounted() {\n var _arguments2 = arguments;\n var vm = this;\n var jq = vm.jq;\n var $el = jq(vm.$refs.table); // you can access and update the vm.options and $el here before we create the DataTable\n\n vm.$emit('table-creating', vm, $el);\n vm.dataTable = $el.DataTable(vm.options);\n\n if (vm.selectCheckbox) {\n // handle select all checkbox\n $el.on('click', 'th input.select-all-checkbox', function (e) {\n if (jq(e.target).is(':checked')) {\n vm.dataTable.rows().select();\n } else {\n vm.dataTable.rows().deselect();\n }\n }); // handle individual row select events\n\n vm.dataTable.on('select deselect', function () {\n var $input = $el.find('th input.select-all-checkbox');\n\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 } // TODO: vm.$emit the selected row?\n\n });\n } // wire up edit, delete, and/or action buttons\n\n\n $el.on('click', '[data-action]', function (e) {\n e.preventDefault();\n e.stopPropagation();\n var target = jq(e.target);\n var that = target;\n var action = that.attr('data-action');\n\n while (!action) {\n // don't let it propagate outside of container\n if (that.hasClass('vdtnet-container') || that.prop('tagName') === 'table') {\n // no action, simply exit\n return;\n }\n\n that = that.parent();\n action = that.attr('data-action');\n } // only emit if there is action\n\n\n if (action) {\n // detect if row action\n var tr = that.closest('tr');\n\n if (tr) {\n if (tr.attr('role') !== 'row') {\n tr = tr.prev();\n }\n\n var row = vm.dataTable.row(tr);\n var data = row.data();\n vm.$emit(action, data, row, tr, 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, null, null, null, target);\n }\n }\n }); // handle master/details\n\n if (vm.details) {\n // default to render function\n var renderFunc = vm.details.render; // must be string template\n\n if (vm.details.template) {\n renderFunc = vm.compileTemplate(vm.details.template);\n } else if (renderFunc) {\n renderFunc = function renderFunc() {\n return vm.details.render.apply(vm, _arguments2);\n };\n } // handle master/details\n // Add event listener for opening and closing details\n\n\n $el.on('click', 'td.details-control', function (e) {\n e.preventDefault();\n e.stopPropagation();\n var target = jq(e.target);\n var that = target;\n var tr = that.closest('tr');\n\n if (tr.attr('role') !== 'row') {\n tr = tr.prev();\n }\n\n var row = vm.dataTable.row(tr);\n\n if (row.child.isShown()) {\n // This row is already open - close it\n row.child.hide();\n tr.removeClass('master');\n } else {\n // Open this row\n var data = row.data();\n row.child(renderFunc(data, 'child', row, tr)).show();\n tr.addClass('master');\n }\n });\n }\n\n vm.$emit('table-created', vm); // finally, load data\n\n if (vm.dataLoader) {\n vm.reload();\n }\n },\n beforeDestroy: function beforeDestroy() {\n var vm = this;\n\n if (vm.dataTable) {\n vm.dataTable.destroy(true);\n }\n\n vm.dataTable = null;\n },\n methods: {\n /**\n * Vue.compile a template string and return the compiled function\n *\n * @param {String} template the string template\n * @return {Function} the compiled template function\n */\n compileTemplate: function compileTemplate(template) {\n var vm = this;\n var jq = vm.jq;\n var res = Vue.compile(\"