Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vue-draggable-grid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Libraries
vue-draggable-grid
Commits
e6553ad8
Commit
e6553ad8
authored
2 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Use v-model instead of defining items inside grid
parent
4853a40a
No related branches found
No related tags found
1 merge request
!2
Resolve "Implement basic functionality"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
example/src/App.vue
+23
-1
23 additions, 1 deletion
example/src/App.vue
src/Grid.vue
+12
-20
12 additions, 20 deletions
src/Grid.vue
with
35 additions
and
21 deletions
example/src/App.vue
+
23
−
1
View file @
e6553ad8
...
...
@@ -4,7 +4,7 @@ import Grid from "../../src/Grid.vue";
<
template
>
<div
id=
"app"
>
<Grid
:rows=
"10"
:cols=
"5"
:pos-validation=
"blockField"
>
<Grid
:rows=
"10"
:cols=
"5"
:pos-validation=
"blockField"
v-model=
"items"
>
<div
id=
"blocker"
>
This field is blocked because it's filled, the next one programmatically
</div>
...
...
@@ -22,6 +22,28 @@ export default {
return
key
!==
"
obj8
"
;
},
},
data
()
{
return
{
items
:
[
{
x
:
1
,
y
:
3
,
w
:
1
,
h
:
1
,
key
:
"
obj1
"
,
data
:
{}
},
{
x
:
2
,
y
:
1
,
w
:
1
,
h
:
1
,
key
:
"
obj2
"
,
data
:
{}
},
{
x
:
3
,
y
:
1
,
w
:
2
,
h
:
2
,
key
:
"
obj3
"
,
data
:
{}
},
{
x
:
5
,
y
:
2
,
w
:
1
,
h
:
1
,
key
:
"
obj4
"
,
data
:
{}
},
{
x
:
1
,
y
:
1
,
w
:
1
,
h
:
2
,
key
:
"
obj5
"
,
data
:
{}
},
{
x
:
5
,
y
:
1
,
w
:
1
,
h
:
1
,
key
:
"
obj6
"
,
data
:
{}
},
{
x
:
2
,
y
:
2
,
w
:
1
,
h
:
3
,
key
:
"
obj7
"
,
data
:
{}
},
{
x
:
1
,
y
:
4
,
w
:
1
,
h
:
1
,
key
:
"
obj8
"
,
data
:
{
title
:
"
I'm blocked from moving!
"
},
},
{
x
:
5
,
y
:
3
,
w
:
1
,
h
:
1
,
key
:
"
obj9
"
,
data
:
{}
},
],
};
},
};
</
script
>
...
...
This diff is collapsed.
Click to expand it.
src/Grid.vue
+
12
−
20
View file @
e6553ad8
...
...
@@ -8,7 +8,7 @@
<div
id=
"highlight"
ref=
"highlight"
></div>
</slot>
<DragContainer
v-for=
"item in
items
"
v-for=
"item in
value
"
:key=
"item.key"
:drag-i-d=
"item.key"
:x=
"item.x"
...
...
@@ -30,6 +30,7 @@ export default {
components
:
{
DragContainer
,
},
emits
:
[
"
input
"
],
props
:
{
rows
:
{
type
:
Number
,
...
...
@@ -43,6 +44,10 @@ export default {
type
:
Function
,
required
:
false
,
},
value
:
{
type
:
Array
,
required
:
true
,
},
},
methods
:
{
positionAllowed
(
x
,
y
,
key
)
{
...
...
@@ -50,7 +55,7 @@ export default {
if
(
x
>
this
.
cols
)
return
false
;
if
(
y
>
this
.
rows
)
return
false
;
for
(
let
item
of
this
.
items
)
{
for
(
let
item
of
this
.
value
)
{
if
(
key
===
item
.
key
)
continue
;
if
(
x
>=
item
.
x
&&
x
<
item
.
x
+
item
.
w
)
{
if
(
y
>=
item
.
y
&&
y
<
item
.
y
+
item
.
h
)
{
...
...
@@ -107,8 +112,9 @@ export default {
if
(
!
newPositionValid
)
return
;
this
.
items
.
splice
(
this
.
items
.
findIndex
((
i
)
=>
{
let
valueCopy
=
structuredClone
(
this
.
value
);
valueCopy
.
splice
(
valueCopy
.
findIndex
((
i
)
=>
{
return
i
.
key
===
element
.
key
;
}),
1
...
...
@@ -116,7 +122,8 @@ export default {
element
.
x
=
coords
.
x
;
element
.
y
=
coords
.
y
;
this
.
items
.
push
(
element
);
valueCopy
.
push
(
element
);
this
.
$emit
(
"
input
"
,
valueCopy
);
},
getCoords
(
x
,
y
)
{
return
{
...
...
@@ -125,21 +132,6 @@ export default {
};
},
},
data
()
{
return
{
items
:
[
{
x
:
1
,
y
:
3
,
w
:
1
,
h
:
1
,
key
:
"
obj1
"
,
data
:
{}
},
{
x
:
2
,
y
:
1
,
w
:
1
,
h
:
1
,
key
:
"
obj2
"
,
data
:
{}
},
{
x
:
3
,
y
:
1
,
w
:
2
,
h
:
2
,
key
:
"
obj3
"
,
data
:
{}
},
{
x
:
5
,
y
:
2
,
w
:
1
,
h
:
1
,
key
:
"
obj4
"
,
data
:
{}
},
{
x
:
1
,
y
:
1
,
w
:
1
,
h
:
2
,
key
:
"
obj5
"
,
data
:
{}
},
{
x
:
2
,
y
:
3
,
w
:
1
,
h
:
1
,
key
:
"
obj6
"
,
data
:
{}
},
{
x
:
2
,
y
:
2
,
w
:
1
,
h
:
3
,
key
:
"
obj7
"
,
data
:
{}
},
{
x
:
1
,
y
:
4
,
w
:
1
,
h
:
1
,
key
:
"
obj8
"
,
data
:
{}
},
{
x
:
5
,
y
:
3
,
w
:
1
,
h
:
1
,
key
:
"
obj9
"
,
data
:
{}
},
],
};
},
};
</
script
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment