File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
45
45
- [ Touch devices support] ( #touch-devices-support )
46
46
- [ Use with knockout.js] ( #use-with-knockoutjs )
47
47
- [ Change grid width] ( #change-grid-width )
48
+ - [ Save grid to array] ( #save-grid-to-array )
48
49
- [ Load grid from array] ( #load-grid-from-array )
49
50
- [ Override resizable/draggable options] ( #override-resizabledraggable-options )
50
51
- [ IE8 support] ( #ie8-support )
@@ -472,6 +473,29 @@ For 4-column grid it should be:
472
473
473
474
and so on.
474
475
476
+ ## Save grid to array
477
+
478
+ Because gridstack doesn't track any kind of user-defined widget id there is no reason to make serialization to be part
479
+ of gridstack API. To serialize grid you can simply do something like this (let's say you store widget id inside ` data-custom-id `
480
+ attribute):
481
+
482
+ ``` javascript
483
+ var res = _ .map ($ (' .grid-stack .grid-stack-item:visible' ), function (el ) {
484
+ el = $ (el);
485
+ var node = el .data (' _gridstack_node' );
486
+ return {
487
+ id: el .attr (' data-custom-id' ),
488
+ x: node .x ,
489
+ y: node .y ,
490
+ width: node .width ,
491
+ height: node .height
492
+ };
493
+ });
494
+ alert (JSON .stringify (res));
495
+ ```
496
+
497
+ You can also use ` onchange ` event if you need to save only changed widgets right away they have been changed.
498
+
475
499
## Load grid from array
476
500
477
501
``` javascript
@@ -497,6 +521,8 @@ _.each(serialization, function (node) {
497
521
});
498
522
```
499
523
524
+ If you're using knockout there is no need for such method at all.
525
+
500
526
## Override resizable/draggable options
501
527
502
528
You can override default ` resizable ` /` draggable ` options. For instance to enable other then bottom right resizing handle
You can’t perform that action at this time.
0 commit comments