3

I am developing a custom extension for Azure DevOps work item. I'm building the extension in React using the azure-devops-ui package. I need to have a table as a part of this extension where I would be able to drag and drop the rows, so as to reorder them. The order is important for my usecase. The documentation says that drag and drop is supported, but doesn't have any further details. I would like to know if there is any property on the Table component that I could use. Screenshot

4
  • 1
    I was able to get this done. Will provide more updates when I have the code available to share. Commented Jul 30, 2020 at 7:09
  • 1
    Glad to know you've found the answer to this issue? You could consider adding it as answer so that members with similar issue in this forum can benefit from that! Commented Jul 31, 2020 at 8:56
  • 2
    Sure. I thought of raising a PR to the azure-devops-extension-samples repo. But I think I can add an answer for now and then update it later. Commented Jul 31, 2020 at 9:23
  • 2
    So @SaleelAli can you add and answer? Commented Oct 12, 2020 at 13:45

2 Answers 2

1

Here's how you can do it. Fill in the place holders as needed and omit any property that may not be needed for your case. I hope this should be enough to get anyone started.

Credit to John Wilkes who helped me find the solution.

import { BoltListDragEvent, IListDropData, ListDragDropBehavior, ListDragImage} from "azure-devops-ui/List";
import { DragAndDropGripper, Table } from "azure-devops-ui/Table";

const onDragEnd = (event: BoltListDragEvent<HTMLElement, ILocationTableItem>) => {
    console.log("Dragged from " + event.detail.dataTransfer.secondaryData.index + " - (" + event.detail.dataTransfer.dropEffect + ")");
};

const onDrop = (event: BoltListDragEvent<HTMLElement, ILocationTableItem>, dropData: IListDropData) => {
    console.log("Dropped at " + dropData.index);
};

const dragDropBehavior = new ListDragDropBehavior<IMyTableItem>({
    allowedTypes: ["MyType"],
    id: "myTableId",
    onDragEnd: onDragEnd,
    onDrop: onDrop,
    renderDragImage: event => <ListDragImage text={event.detail.dataTransfer.data.myProperty} />,
    type: "MyType"
});

function renderGripper(index: number, left: boolean) {
    if (left) {
        return <DragAndDropGripper />;
    }
    return null;
}

<Table
    behaviors={[dragDropBehavior]}
    columns={myColumns}
    itemProvider={myTableItemProvider}
    onActivate={(event, data) => console.log("Activate Row - " + data.index)}
    renderSpacer={renderGripper}
/>
Sign up to request clarification or add additional context in comments.

Comments

0

@SaleelAli, you never actually posted the answer. It would greatly help the community if you can post your findings on this. Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.