pavankataria / SwiftDataTables

A Swift Data Table package, display grid-like data sets in a nicely formatted table for iOS. Subclassing UICollectionView that allows ordering, and searching with extensible options.
MIT License
448 stars 69 forks source link

Drag and drop to reorder rows #40

Open kvenkata1974 opened 5 years ago

kvenkata1974 commented 5 years ago

Hi, I'm using version 0.8 of SwiftDataTables.

Can the rows not be reorder via drag and drop?

Was hoping the delegate would allow for drag and drop of rows.

Cheers Karthik

kvenkata1974 commented 5 years ago

I should be using the drag and drop delegate of the collection view, will try that first.

kvenkata1974 commented 5 years ago

Sorry, tried using UICollectionViewDelegate and implemented the methods (extended SwiftDataTable since it already implements the protocol):

func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
    return true
}

func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    print("Starting Index: \(sourceIndexPath.item)")
    print("Ending Index: \(destinationIndexPath.item)")
}

But I could not get reorder of items via drag and drop to be triggered. Please help.

pavankataria commented 5 years ago

Yeah I didn't have this in mind and not sure how adopting those methods will affect the ordering of the swift data tables datasource. Come to think of it, I believe you'll need to update the datasource yourself once you figure out where the user wants to drag and drop an item. You'll then need to refresh the collection view to reflect the changes.