Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gridstack basics, how to make the demo work

Really noob question, but I don't understand what am I doing wrong here ?

<head>
    <link rel="stylesheet" type="text/css" href="gridstack.js/dist/gridstack.css">
</head>

<body>
    <div class="grid-stack">
        <div class="grid-stack-item" 
            data-gs-x="0" data-gs-y="0" 
            data-gs-width="4" data-gs-height="2">
                <div class="grid-stack-item-content"> azazfaz</div>
        </div>
        <div class="grid-stack-item" 
            data-gs-x="4" data-gs-y="0" 
            data-gs-width="4" data-gs-height="4">
                <div class="grid-stack-item-content"></div>
        </div>
    </div>
</body>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"> </script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"> </script>
<script type="text/javascript" src="gridstack.js/dist/gridstack.js"> </script>

<script type="text/javascript">
    $(function () {
        var options = {
            cell_height: 80,
            vertical_margin: 10
        };
        $('.grid-stack').gridstack(options);
    });
</script>

I get this error:

gridstack.js:391 Uncaught TypeError: undefined is not a function

pointing to this line in gridstack:

  var is_nested = this.container.closest('.' + opts.item_class).size() > 0;

EDIT: I found the problem, if I replace this lines

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"> </script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>

by

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>

then it works , any idea why ?

like image 854
François Richard Avatar asked Jan 08 '23 03:01

François Richard


2 Answers

As a workaround, you can do the following to make gridstack work when the size() function doesn't exist:

$.fn.size = function(){
  return this.length;
};
like image 89
James Thurley Avatar answered Jan 09 '23 20:01

James Thurley


jQuery 3.0 removes the jQuery.fn.size method. It's probably safer to just stick with 1.11.x when using this library.

https://github.com/jquery/jquery/issues/1749

(BTW I actually get this.container.closest(...).size is not a function as the reported error).

like image 41
jeff carey Avatar answered Jan 09 '23 18:01

jeff carey