I want to be able to move the row and have it save the sort order to an attribute called "sortId". I have a tableview bound with a dataCollection.
For example: If I have 30 elements in the table each one will have a sortId of 1-30 in the correct order. If I move the fifth to the first position it should re-sort the tableview and re-assign the correct sortId to all objects so I can correctly display them on another tableView in the correct order.
I saw something similar to this question and answer: https://developer.appcelerator.com/question/150577/alloy-databinding-tableview-row-to-model-position-in-collection
But that solution only seemed to update the current row. I can't seem to figure out how to get it to re-sort the entire tableView and refresh it.
I ended up doing this code on the close button of the window that contains the tableview. It works but seems awfully wrong and takes some time for it to save all of the models before closing the window.
$.closeBtn.addEventListener('click', function () { var devices = Alloy.Collections.device; var i = 0; $.win.close(); if($.devicesTableView.data[0]) { var deviceTvData = $.devicesTableView.data[0].rows; //todo: Reordering the devices but there has to be a better way to do this... _.each(deviceTvData, function (d) { var model = devices.get(d.alloy_id); model.save({sortId: i}); i++; }); } });Any ideas on a better way to do this? Thanks.