Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
open-source
gridstack.js
Commits
ddeec2c8
Commit
ddeec2c8
authored
Nov 11, 2014
by
Pavel Reznikov
Browse files
knockout.js sample
parent
a5ef8427
Changes
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
ddeec2c8
...
...
@@ -17,6 +17,55 @@ Usage
Coming soon...
## Use with knockout.js
```
javascript
ko
.
components
.
register
(
'
dashboard-grid
'
,
{
viewModel
:
{
createViewModel
:
function
(
params
,
componentInfo
)
{
var
ViewModel
=
function
(
params
,
componentInfo
)
{
var
grid
=
null
;
this
.
widgets
=
params
.
widgets
;
this
.
afterAddWidget
=
function
(
items
)
{
_
.
each
(
items
,
function
(
item
)
{
item
=
$
(
item
);
if
(
item
.
data
(
'
_gridstack_node
'
))
return
;
if
(
grid
==
null
)
{
grid
=
$
(
componentInfo
.
element
).
find
(
'
.grid-stack
'
).
gridstack
({
auto
:
false
}).
data
(
'
gridstack
'
);
}
grid
.
add_widget
(
item
);
},
this
);
};
};
return
new
ViewModel
(
params
,
componentInfo
);
}
},
template
:
[
'
<div class="grid-stack">
'
,
'
<!-- ko foreach: widgets, afterRender: afterAddWidget -->
'
,
'
<div class="grid-stack-item" data-bind="attr: {
\'
data-gs-x
\'
: x,
\'
data-gs-y
\'
: y,
\'
data-gs-width
\'
: width,
\'
data-gs-height
\'
: height}"><span data-bind="text: $index"></span></div>
'
,
'
<!-- /ko -->
'
,
'
</div>
'
].
join
(
'
\n
'
)
});
```
and HTML:
```
html
<div
data-bind=
"component: {name: 'dashboard-grid', params: $data}"
></div>
```
License
=======
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment