framework7 icon indicating copy to clipboard operation
framework7 copied to clipboard

A working example for swipeout-delete on virtual-list

Open ytbryan opened this issue 9 years ago • 3 comments

Hi there, thank you for framework7. Is there an existing example to demonstrate swipeout-delete on a virtual-list to successfully update the virtual-list after the delete event?

Currently, I am facing either a single empty row (after delete) or an entire empty virtual-list (when i use .update() or .deleteItem())

Any advice? Appreciate your help in advance! I have also filed the question to stackoverflow

ytbryan avatar Aug 15 '17 01:08 ytbryan

 render :
 return '<li class="swipeout"> ' +
            ' <div class="swipeout-content"> ' +
                ' <a href="#" class="item-content item-link item-notifications"> ' +
                'notification content' +
                ' </a> ' +
            ' </div> ' +
            ' <div class="swipeout-actions-right"> ' +
                ' <a href="#" class="swipeout-delete swipeout-overswipe" onclick="deleteNotification(' + 
   notification.NotificationID + ');">delete</a> ' +
            '  </div> ' +
           ' </li>';

 var deleteNotification = function (id) {
 for (var i = 0; i < notifications.vl.items; i++) {
    var temp = notifications.vl.items[i];
    if (temp.NotificationID == id) {
        notifications.vl.deleteItem(i);
        break;
    }
  }
 }

not the best practice but a work around with for loop when swipe out fire delete

mohshraim avatar Aug 20 '17 10:08 mohshraim

Thanks for the answer @mohshraim

In the end, I use the following solution:

At virtual-list:

                    onItemBeforeInsert: function(list,item){
                        if($$(item).hasClass("added") == false){
                            $$(item).on('swipeout:delete', function (e) {
                                           ///update webservice    
                            })
                            $$(item).addClass("added")
                        }
                    }

At javascript

function complete_button(time){  
  for(var i = 0; i < index_vl.items.length; i++){
    if(index_vl.items[i].created_at == time){
      index_vl.deleteItem(i)
      index_vl.update()
      break
    }
  }
}

At template

<a id="complete_button" onclick="complete_button('{{created_at}}')"
          class="demo-actions bg-green swipeout-delete swipeout-overswipe">
            <span class="small">Complete</span>
</a>

ytbryan avatar Aug 21 '17 12:08 ytbryan

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jun 25 '18 00:06 lock[bot]