Skip to content

Commit 4f4c090

Browse files
committed
Added responseiveLauouts to explicitly set all layouts per breakpoint
Added 'breakpoint-changed' event to notify in case of value change in breakpoint.
1 parent 6d756de commit 4f4c090

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ Include the browser-ready bundle (download from [releases](https://github.com/jb
175175

176176
The value must be an `Array` of `Object` items. Each item must have `i`, `x`, `y`, `w` and `h` properties. Please refer to the documentation for `GridItem` below for more information.
177177

178+
* **responsiveLayouts**
179+
180+
* type: `Object`
181+
* required: `false`
182+
* default : `{}`
183+
184+
This is the initial layouts of the grid per breakpoint if `responsive` is set to `true`.
185+
The `Object` keys are breakpoint names and each values is an `Array` of `Object` items as defined by `layout` prop. eg:{ lg:[layout items], md:[layout items] }.
186+
If it is set after the layout creation, it replaces the layout configuration in all breakpoints
187+
178188
* **colNum**
179189

180190
* type: `Number`
@@ -469,6 +479,7 @@ Working example [here](https://jbaysolutions.github.io/vue-grid-layout/examples/
469479
@layout-mounted="layoutMountedEvent"
470480
@layout-ready="layoutReadyEvent"
471481
@layout-updated="layoutUpdatedEvent"
482+
@breakpoint-changed="breakpointChangedEvent"
472483
>
473484

474485
<grid-item v-for="item in layout"
@@ -626,6 +637,23 @@ Working example [here](https://jbaysolutions.github.io/vue-grid-layout/examples/
626637
},
627638
```
628639

640+
* **breakpointChangedEvent**
641+
642+
Breakpoint Changed event
643+
644+
Every time the breakpoint value changed due to window resize
645+
646+
```javascript
647+
/**
648+
*
649+
* @param newBreakpoint the breakpoint name
650+
*
651+
*/
652+
breakpointChangedEvent: function(newBreakpoint){
653+
console.log("BREAKPOINT CHANGED B=" + newBreakpoint);
654+
},
655+
```
656+
629657

630658
## Contribute
631659

src/components/GridLayout.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
type: Boolean,
9090
default: false
9191
},
92+
responsiveLayouts: {
93+
type: Object,
94+
default: function() {
95+
return {};
96+
}
97+
},
9298
breakpoints:{
9399
type: Object,
94100
default: function(){return{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
@@ -217,6 +223,9 @@
217223
layout: function () {
218224
this.layoutUpdate();
219225
},
226+
responsiveLayouts: function() {
227+
this.layoutUpdate();
228+
},
220229
colNum: function (val) {
221230
this.eventBus.$emit("setColNum", val);
222231
},
@@ -403,6 +412,11 @@
403412
// Store the new layout.
404413
this.layouts[newBreakpoint] = layout;
405414
415+
if (this.lastBreakpoint !== newBreakpoint) {
416+
this.$emit('update:')
417+
this.$emit('breakpoint-changed', newBreakpoint)
418+
}
419+
406420
// new prop sync
407421
this.$emit('update:layout', layout);
408422
@@ -413,7 +427,7 @@
413427
// clear all responsive layouts
414428
initResponsiveFeatures(){
415429
// clear layouts
416-
this.layouts = {};
430+
this.layouts = Object.assign({}, this.responsiveLayouts);
417431
},
418432
419433
// find difference in layouts

0 commit comments

Comments
 (0)