Skip to content

Quickish question: How do you update the number of columns the grid is using dynamically?  #227

Closed

Description

@playingwithbandits

When you create a new grid I know that you can define the number of columns by setting the 'width' in the options array.

For example:
$('.grid-stack').gridstack( {width: 3} );

Is there a way, through jQuery, to update this value to 2 for example.

I have tried:
$('.grid-stack').gridstack({ width: 2 });
$('.grid-stack').data('gridstack').width = 2;

Any ideas? Thanks

Activity

  1. laurentsorin commented on Oct 14, 2015

    @laurentsorin

    Try this :
    $('.grid-stack').data('gridstack').grid.width = 2;

    It's a little hack (because it doesn't use a public method...)

    And don't forget to change css class in the grid to grid-stack-2

  2. radiolips commented on Feb 19, 2016

    @radiolips
    Member

    We can expose a method to modify this on the fly, but as @Booster78 says, you'll also need to change the CSS.

  3. added this to the v0.2.5 milestone on Feb 19, 2016
  4. added a commit that references this issue on Feb 20, 2016
  5. radiolips commented on Feb 20, 2016

    @radiolips
    Member

    Using gridstack v.0.2.5 you may now use the grid's .setGridWidth method to change the number of columns on the fly. You will not need to alter any CSS. If you already have widgets on the dashboard, it will attempt to resize/reposition them to retain their aspect ratios. Please note that the reposition/resize feature is experimental for the time being. You will see odd behavior when switching from 12 columns to 11, for example.
    Example usage:
    $('.grid-stack').data('gridstack').grid.setWidth(2); // set number of columns to 2.

  6. luckylooke commented on Sep 6, 2017

    @luckylooke
    Contributor

    Example usage should be:
    $('.grid-stack').data('gridstack').setGridWidth(2); // set number of columns to 2.
    but it is buggy.. there should be a method for global fix of collisions because some grid changes causes items to overlap. :/

  7. luckylooke commented on Oct 26, 2017

    @luckylooke
    Contributor

    setGridWidth seems to be working now, it had to be different problem causing items to overlap 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions