0

我正在尝试使网格静态化。一点动静都没有。

我试过了:

var options = {
        staticGrid: true,
    };
    $('.grid-stack').gridstack(options);

还有这个

 var options = {
        setStatic: true,
    };
    $('.grid-stack').gridstack(options);

和这个

var options = {
        staticGrid: true,
    };
    $('.grid-stack').gridstack(options);
    $('.grid-stack').data('gridstack').setStatic(true);

它们似乎都不起作用,我使用此链接获取文档。

他们还提到了setStatic方法,但没有使用此方法的示例。

4

1 回答 1

1

According to the Gridstack docs the staticGrid:true parameter is correct if you want to initialise and define the grid as STATIC at startup (your first method).

The SetStatic(true) is a function you can call on for toggling this state programatically.

If you view the source code live you will see a new CSS class has been added to the grid wrapper DIV; a class called 'grid-stack-static'. The appearance of this class confirms the parameter option staticGrid:true has been accepted and actioned.

BUT as I found myself (with v0.30 of the library), grid widgets in my initialised grid are still resizable and movable. In my opinion this suggests a bug.

You can lock down movement and resizing at a widget item level by using the item attributes data-gs-no-resize="yes" and data-gs-no-move="yes".

Seems counterproductive to have to do this if you have said 'static' already.

I have lodged an issue on Github to query this behaviour.

BTW it has been suggested to call on and use the setStatic( true ) function after grid init; as a temporary fix for this bug. Which was your third method - AND this worked for me.

Only difference between your 3rd method and mine is the function is wrapped in a document.ready function (and I am using $=jquery shortcut for convenience/compatibility on my system).

Worked:

(function ($) { 
  // Shortcut $=jquery

    $(document).ready(function () {
      // start grid

      $(function () {
        var options = {
             staticGrid:true
          };
         $('.grid-stack').gridstack(options);

         $('.grid-stack').data('gridstack').setStatic( true );
      });

    // END DOC READY
    }); 
// SHORTCUT FIX
})( jQuery ); 

于 2017-08-21T06:46:48.063 回答