ES6/webpack environment import editor plugin
ES6/webpack environment import editor plugin
connexo
Posts: 10Questions: 1Answers: 0
In our current project we're creating native web components. Amongst those is a datatable webcomponent, an extremely stripped-down version of which looks like this:
import $ from 'jquery';
import 'datatables.net';
import 'datatables.net-select';
import editor from './editor-datatables/js/dataTables.editor'
class DataTable extends HTMLElement {
/* lots of setup code */
connectedCallback() {
console.log($.fn.dataTable.Editor); // returns undefined
}
}
window.customElements.define('data-table', DataTable);
When we try to to initialize the editor as described in the documentation var editor = new $.fn.dataTable.Editor();
, we're getting
Uncaught TypeError: jquery_default.a.fn.dataTable.Editor is not a constructor
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Here's a StackBlitz showcasing the problem:
https://stackblitz.com/edit/js-kedml1
Thanks for the StackBlitz link. Cool platform that - hadn't seen it before.
Three things going on here, which the following should fix:
datatables.js
file.window.jQuery
manually. Editor looks for a globaljQuery
variable - I'll see what I can do about that.editor
like with thedt
variable. The return isn't particularly important since it attaches the Editor constructor into jQuery.Allan
Thanks for the quick reply. I corrected the path error but still cannot get it to work - looks like Stackblitz doesn't even allow creating global variables.
Feel free to fork the StackBlitz and try to create a working version.
Now I have a version that doesn't report any console errors any more, yet clicking a
td
won't make the field editable. Can you please be so kind and quickly take a look?https://stackblitz.com/edit/js-kedml1
@allan Not sure if a mention is necessary so you notice the new comments.
Allan is good about following up. He is busy and in the UK
I've not seen stackblitz either. Pretty cool, thanks for the pointer. There is a console log error when clicking on a row:
Uncaught (in promise) Error: Cannot parse given Error object
I figured this meant that stackblitz wouldn't provided alert messages so I surmised that you were getting this error.
https://datatables.net/manual/tech-notes/14
I added
idSrc
for Editor androwId
for Datatables. Plus I changed you Datatablescolumns.data
to match the 'name' of the field in the Editor.Try your updated example:
https://stackblitz.com/edit/js-5bi3hk?file=index.js
Kevin
Actually I wasn't getting any console errors any more (Chrome 70, Win). Thanks for fixing the StackBlitz example. Will give it a ride in the real world now.
Now, when I change a cell, and press enter, I'm getting
You need to update your DataTables install. There was a fix a while back in Editor that needed updates to both DataTables and Editor. If you update to the latest version of DataTables, that issue should be resolved.
Allan
The version being used in that StackBlitz is 2.1.1. Is there a newer version available? Also, the editor version is from like 5 days ago.
The other problem with the otherwise working StackBlitz is if I edit a cell, and then click on another, the changes I did in the first cell are being reverted.
https://stackblitz.com/edit/js-2tw4bs
Please ignore my last question/comment. I wasn't aware that for the changes to take effect you have to press enter. Is this configurable?
Hi @connexo ,
Yep, all configurable - see
formOptions.inline
. The one you want isonBlur
, seeform-options
,Cheers,
Colin