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

Inline Editors not working after component destroy in Angular #86

Open
AntoRin opened this issue Dec 2, 2022 · 7 comments
Open

Inline Editors not working after component destroy in Angular #86

AntoRin opened this issue Dec 2, 2022 · 7 comments

Comments

@AntoRin
Copy link

AntoRin commented Dec 2, 2022

Dhtmlx-gantt version: 7.1.13

I am using the free version of dhtmlx-gantt. This means that I won't be able to initialize a new gantt instance on component render. I perform some clean-up of the gantt instance on destroy, which is mostly removing all events and tooltips. Although this has been working well so far, the inline editors only work the first time. After the first time, none of the events related to the inline events fire (events that are created using the gantt.ext.inlineEditors.attachEvent method).

@AntoRin
Copy link
Author

AntoRin commented Dec 7, 2022

I've found out that using the gantt.init method on an already initialized gantt instance makes the inline editors unusable.

Any workarounds for this?

@gearcoded
Copy link

@AntoRin,
It is a bug in Gantt that the inline editor events stop working after using the init and resetLayout methods. The dev team will fix the bug in the future, but I cannot give you any ETA.

As a workaround, you can detach events and attach them again in the onGanttReady event handler:

var onSave_id = null;
gantt.attachEvent("onGanttReady", function () {
  if (onSave_id) gantt.ext.inlineEditors.detachEvent(onSave_id)

  onSave_id = gantt.ext.inlineEditors.attachEvent("onSave", function (state) {
    gantt.message("onSave event");
    var col = state.columnName;
    if (gantt.autoSchedule && (col == "start_date" || col == "end_date" || col == "duration")) {
      gantt.autoSchedule();
    }
  });
});

Here is the snippet:
https://snippet.dhtmlx.com/5/a6ca5c108

@AntoRin
Copy link
Author

AntoRin commented Dec 12, 2022

Hi, @gearcoded, thanks for the reply.

This solution works. Although I was already detaching inline editor events when the component destorys, I wasn't attaching them back during the onGanttReady event. Apparently, that's necessary.

And for those who are referring to this later on, you can use the following method to detach all events from the inline editor instead of having to store reference to each event using the returned event ID and detaching them one by one.

gantt.ext.inlineEditors.detachAllEvents();

@AntoRin AntoRin closed this as completed Dec 12, 2022
@CedricHg
Copy link

CedricHg commented Oct 6, 2023

@AntoRin, It is a bug in Gantt that the inline editor events stop working after using the init and resetLayout methods. The dev team will fix the bug in the future, but I cannot give you any ETA.

As a workaround, you can detach events and attach them again in the onGanttReady event handler:

var onSave_id = null;
gantt.attachEvent("onGanttReady", function () {
  if (onSave_id) gantt.ext.inlineEditors.detachEvent(onSave_id)

  onSave_id = gantt.ext.inlineEditors.attachEvent("onSave", function (state) {
    gantt.message("onSave event");
    var col = state.columnName;
    if (gantt.autoSchedule && (col == "start_date" || col == "end_date" || col == "duration")) {
      gantt.autoSchedule();
    }
  });
});

Here is the snippet: https://snippet.dhtmlx.com/5/a6ca5c108

This snippet no longer works on the current version of DHTMLX Gantt, because the attachEvent function for InlineEditorEvents now returns a boolean rather than a string id. I have not yet been able to find how I can get this id in the current version for detaching purposes.

@gearcoded gearcoded reopened this Oct 9, 2023
@AntoRin
Copy link
Author

AntoRin commented Oct 9, 2023

@AntoRin, It is a bug in Gantt that the inline editor events stop working after using the init and resetLayout methods. The dev team will fix the bug in the future, but I cannot give you any ETA.
As a workaround, you can detach events and attach them again in the onGanttReady event handler:

var onSave_id = null;
gantt.attachEvent("onGanttReady", function () {
  if (onSave_id) gantt.ext.inlineEditors.detachEvent(onSave_id)

  onSave_id = gantt.ext.inlineEditors.attachEvent("onSave", function (state) {
    gantt.message("onSave event");
    var col = state.columnName;
    if (gantt.autoSchedule && (col == "start_date" || col == "end_date" || col == "duration")) {
      gantt.autoSchedule();
    }
  });
});

Here is the snippet: https://snippet.dhtmlx.com/5/a6ca5c108

This snippet no longer works on the current version of DHTMLX Gantt, because the attachEvent function for InlineEditorEvents now returns a boolean rather than a string id. I have not yet been able to find how I can get this id in the current version for detaching purposes.

Hey, @CedricHg, thanks for the reply. I have been using this solution for a while now following @gearcoded 's advice. Seems to be working fine. Although let me know when this is totally resolved.

@gearcoded
Copy link

@AntoRin and @CedricHg, that seems to be an issue with the types, though the attachEvent function should work correctly.
In fact, it is not necessary to save the IDs of the event handlers for the inline editors. It can work if you don't do that. The only difference is that the event handler ID will be different.
So, as a workaround, you can attach the inline editor events in the onGanttReady event handler:

gantt.attachEvent("onGanttReady", function () {
    gantt.ext.inlineEditors.attachEvent("onEditStart", function (state) {
        if (state.columnName == "progress") {
            const node = gantt.ext.inlineEditors._placeholder.firstChild.firstChild
            node.value = parseInt(node.value * 100);
        }
    });
});

And here is the snippet:
https://snippet.dhtmlx.com/be56ezhd

I will notify you when the issue is fixed.

@AntoRin
Copy link
Author

AntoRin commented Nov 4, 2023

@gearcoded, appreciate that. Thank you.

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

3 participants