Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

es module build #4

Open
wdporter opened this issue Sep 21, 2022 · 6 comments
Open

es module build #4

wdporter opened this issue Sep 21, 2022 · 6 comments

Comments

@wdporter
Copy link

Is the es module build hosted anywhere? I'd like to use it like this:

<script type="module">
  import DataTable from "/javascripts/datatables.net-vue.esm.js"
</script>
@AllanJard
Copy link
Contributor

@AllanJard
Copy link
Contributor

The rest of DataTables doesn't yet support ES module loading. I'm working on that.

@wdporter
Copy link
Author

I got this to work.
at the top of your js I had to change it to

import { defineComponent, setBlockTracking, createElementVNode, normalizeClass, renderSlot } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';

and then my html is:

<div id="app">
	<data-table :data="data" class="display"
	:options="{columns: [{title: 'A'}, {title: 'B'}]}">		
	<thead><tr><th>ab</th><th>cd</th></tr></thead>
	</data-table>
</div>

<script type="module">
import DataTable from "./vue3dt.esm.js" // my edited local copy of datatables.net-vue.esm.js .
import { createApp } from "https://unpkg.com/vue@3/dist/vue.esm-browser.js" 
createApp({
	components: {
		DataTable
	},
	setup() {
		return {
			data: [[1,2], [3,4]]
		}
	},
}).mount('#app')
</script>

The result of the thead slot is unexpected, I get the text concatenated and then it's just added as textContent to the table element. No th elements were rendered until I supplied the columns options.

I'm not sure if I'm doing something wrong, or if it's not complete yet, or if the doco is wrong, or if I'm crazy for even trying this.

@AllanJard
Copy link
Contributor

I don't see anything obviously wrong there. Can you give me a link to a test case showing the issue, perhaps on JSFiddle or some other code platform?

@wdporter
Copy link
Author

wdporter commented Sep 23, 2022

https://oldman.neocities.org/data-tables-vue-es-module-build.html

it's more the fact that when I declare the <thead> element in the slot, I get the error message:
Uncaught TypeError: aoColumns[srcCol] is undefined
(but you don't see that in the codepen console, you need the browser console)

it's a bit moot when I can just define columns in the options, and remove the <thead>, but your readme says the <thead> should work. So I don't know if it's an error in the doc or in the js module.

@AllanJard
Copy link
Contributor

Hah - generally when the docs and the code don't align, both are wrong ;-). In this case I believe that it should work with the thead defined in the template. That was certainly the intention! Thanks for the link - I'll look into it. In the meantime, good to hear you've got a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants