Hello everyone,
I’ve run into a problem and am looking for the best way to solve it without altering the Yii2 framework.
I have a page which contains elements that can be sorted. I’m using the yii-jui sortable widget and everything works fine after the initial view.
Under certain circumstances I need to update the content with all the elements per ajax. This too is working.
The problem is that when I update the content after an ajax call the jquery initialization for the sortable elements and their containers is lost.
When building the initial view the yii-jui extension places the javascript for initializing the Sortable elements in a Javascript block within an on-document-ready function. As I already stated this works fine during the first view. However, when I update the content the initializations are lost and somehow I need to run the javascript initialization again. I cannot do this because the on-document-ready function is not triggered.
A possible solution would be to place all the JS initialization for the sortable elements into a separate function and call this explicitly after the first view and also after an ajax update. The difficulty is that I see no way to do this with the yii-jui widget as it places all the initialization (events and options) as singular calls in the on-document-ready function.
I’ve considered the following:
-
Add an option to yii-jui widget to place the initialization steps into a JS function
-
Use a view event hook to manipulate the JS bundle/asset settings prior to building the HTML, so that I can create the function I need
-
Do not use the native options in the yii-jui widget but write a separate initialization script of my own.
Any ideas at how I could best proceed?
Thanks for any input
Andy Potter