2

I'm following this example, trying to implement it in Angular.

I import as follows (no jQuery dependencies):

import * as GridStack from 'gridstack/dist/gridstack-h5';

And the code

ngAfterViewInit() {
    
  var items = [
      {content: 'my first widget'}, // will default to location (0,0) and 1x1
      {w: 2, content: 'another longer widget!'} // will be placed next at (1,0) and 2x1
   ];

    var grid = GridStack.init();
    grid.load(items);
}

But all I see is static divs instead of a grid, and there are no errors. What's missing?

2
  • <link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/> ? Commented Jan 7, 2021 at 12:04
  • I have that, doesn't make any difference Commented Jan 7, 2021 at 12:07

1 Answer 1

2
+100

Please post your HTML template.

Double check your config from GridStack Read Me, if you are using an ngfor then you need to see step 3 and invoke this on your main div $('.grid-stack').gridstack();

  1. You must install:

yarn add gridstack
// or
npm install --save gridstack
  1. You must import it into angular component 2A or 2B for HTML:

  • 2A For your answer Typescript like so:
import 'gridstack/dist/gridstack.min.css';
import GridStack from 'gridstack';

You should now have gridstack-h5.js gridstack native js version like here

  • 2B For others lookging to do it in HTML optional, like so:

    <script src="node_modules/gridstack/dist/gridstack-h5.js"></script>

    <link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/>

  1. What is your HTML template, like here

  ngAfterViewInit() {
        setTimeout(() => {
            $('.grid-stack').gridstack();
            this.gridStack = $('.grid-stack').data('gridstack');
        }, 300); //This MUST finish after dynamic data is retrieved for ngfor, and calling these statements in another area just doesn't work
    }
Sign up to request clarification or add additional context in comments.

7 Comments

Am I forced to use jQuery? The idea of Gridstack 3 is to eliminate the dependency
if you look at my post, you will see three options in step 4 this is native but also very new import 'gridstack/dist/h5/gridstack-dd-native'; . So, to test I would try the other two imports as well one at a time.
meanwhile Gridstack is JQuery free, please look at github.com/gridstack/gridstack.js/blob/develop/…
if you use the option I mentioned above in step 4
I did not understand why the scripts property has to reference jquery. The question is about implementation without jquery. Can you make an example jquery free?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.