gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

Knockout binding not working with drag/resize

Open getrupendra opened this issue 11 years ago • 4 comments

Thanks @troolee for this wonderful work,

I worked on Knockout example provided with demo. The array of widgets is observableArray. The properties of widgets like x, y, width, height etc are also made observable. So that I can change it manually at run time.

It works till the extent that I can change dimensions and positions from text inputs but "How we can change widgets properties with drag/resize so that it gets reflected in viewmodel also".

Basically, I want to save changed properties (using drag/resize) to a server.

Please look at code at https://github.com/getrupendra/gridstack

Thanks in Advance.

getrupendra avatar Jul 27 '15 09:07 getrupendra

The issue is with knockout itself. Attribute binding is not twoway. I worked arround the issue like this: Ps this code is part of a larger 'dashboard' custom binding.

        $dashboard.on('change', function (event, items) {
            _.forEach(items, function (i) {

                var data = ko.dataFor(i.el[0]);
                if (data.XPosition() !== i.x) {
                    data.XPosition(i.x);
                }

                if (data.YPosition() !== i.y) {
                    data.YPosition(i.y);
                }

                if (data.Width() !== i.width) {
                    data.Width(i.width);
                }

                if (data.Height() !== i.height) {
                    data.Height(i.height);
                }

            });
        });

ghost avatar Aug 10 '15 11:08 ghost

I will surely give it a try. Thanks Friso :)

getrupendra avatar Aug 11 '15 08:08 getrupendra

@getrupendra Did you have success? I'm closing this ticket, but feel free to reopen if you still have concerns.

radiolips avatar Feb 18 '16 16:02 radiolips

The answer posted worked for me.

I'm curious, is this a problem that a custom binding would be able to fix? I'm confused as to why Knockout wouldn't list this as a limitation on their website.

rmwever avatar Nov 28 '16 20:11 rmwever