Drag and drop snap grid

I want to snap the grid when we hold it off the palette. How can I do?

snap when I move. I dont want this. I want to get snap when drag and drop

I am unclear what you want. So you do not want for there to be any grid-snapping behavior when dragging within the diagram, is that correct? If so, do not set https://gojs.net/latest/api/symbols/DraggingTool.html#isGridSnapEnabled to true.

But if you still want a drag-and-drop from a Palette into your Diagram to be snapped to the grid, you can implement that in an “ExternalObjectsDropped” DiagramEvent listener.

        $(go.Diagram, . . .,
          {
            . . .,
            "ExternalObjectsDropped": function(e) {
              e.subject.each(function(node) {
                if (node instanceof go.Link) return;
                var grid = e.diagram.grid;
                node.location = node.location.copy().snapToGridPoint(grid.gridOrigin, grid.gridCellSize);
              })
            }
          });
1 Like