Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BIMDataTable canDragOverRow props & logic #283

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/BIMDataComponents/BIMDataTable/BIMDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@
</th>
</tr>
</thead>
<tbody>
<tbody @dragleave="onDragleave">
<tr
v-for="{ key, data } of computedRows"
:key="`body-row-${key}`"
v-show="displayedRows.includes(key)"
:style="{ height: `${rowHeight}px` }"
@drop="$emit('row-drop', { data, event: $event })"
@drop="onDrop(data, $event)"
@dragover="onDragover(key, data, $event)"
:class="{
'bimdata-table__row--drag-overed': dragOveredRowKey === key,
}"
>
<td class="cell-checkbox" v-if="selectable">
<BIMDataCheckbox
Expand Down Expand Up @@ -164,6 +168,10 @@ export default {
type: String,
default: "auto",
},
canDragOverRow: {
type: Function,
default: () => false,
},
},
emits: [
"update:selection",
Expand Down Expand Up @@ -249,6 +257,22 @@ export default {
{ immediate: true }
);

const onDrop = (data, event) => {
if (props.canDragOverRow(data)) {
emit("row-drop", { data, event });
}
};
const dragOveredRowKey = ref(null);
const onDragover = (key, data, event) => {
if (props.canDragOverRow(data)) {
event.preventDefault();
dragOveredRowKey.value = key;
}
};
const onDragleave = () => {
dragOveredRowKey.value = null;
};

return {
// References
computedRows,
Expand All @@ -257,7 +281,11 @@ export default {
pageIndexEnd,
pageIndexStart,
rowSelection,
dragOveredRowKey,
// Methods
onDrop,
onDragover,
onDragleave,
toggleAll,
toggleRow,
};
Expand Down
8 changes: 8 additions & 0 deletions src/web/views/Components/Table/props-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ export default [
"Use this prop to set table-layout css property (e.g. 'auto' or 'fixed').",
"",
],
[
"canDragOverRow",
"Function",
"",
"row => false",
"If returns true, a 'bimdata-table__row--drag-overed' class is added on the row on drag over, and the `row-drop` event is emitted on drop.",
"",
],
];