Open cindyw8686 opened 5 years ago
The toArray
function is giving an ID to each list item based on the html element. If you sort the list and call toArray
again, the result will reflect this change in the list.
If you want a custom ID to correspond to each list item, rather than the one Sortable has generated, set the data-id
on the item's element.
Thank you! I'm not fully understand your solution. Could you please write a sample here?
I got that issue solved by using a temp Array cloneSearchResult to store the original order.
self.RevertAll = function RevertAll() {
if (self.searchList)
{
self.facetsResults = self.cloneSearchResult.map(a => Object.assign({}, a));
return self.facetsResults;
}
};
Here is an example of the HTML:
<ul id="items">
<li data-id="apple">Apple</li>
<li data-id="orange">Orange</li>
<li data-id="banana">Banana</li>
</ul>
Then when you call toArray()
, you will get the order represented by the data-id
s:
sortable.toArray()
// => ['apple', 'orange', 'banana']
I have another question there. I have a checkbox in the list. I check one checkbox, and I move that row. The checkbox value becomes unchecked after the movement is done. How can I get that row moved and with checkbox change together? Should I save the new checkbox value to my temp valuable in onChange or some other functions? I have difficulty to get that row/columns values...
onChoose: function (/*Event/evt) { evt.oldIndex; // element index within parent //console.log("onChoose="+evt.oldIndex); let tmp = evt.item.collapse; //tmp = evt.item.textContent["collapse"]; //console.log("onChoose="+tmp); },
Thanks, Cindy
tr class="list-group" md-row md-select="prod" md-auto-select="true" ng-repeat="facetsResult in fm.facetsResults"
input type="checkbox" ng-checked={{facetsResult['collapse']}} ng-click="fm.collapseChange($index)"
Question:
I'm new to use this. I'd like to get values in new order list. I checked around, I couldn't find a good sample of that. I'm wondering if you can provide me a sample how to get the value.
when I print out in the set function, I got value like this: set:12rs,131v,12qs,13md,13f2,13mx. I'm not sure how to use them?
I tried those and my table got whipped out. self.order = self.searchList.toArray(); return self.facetsResults = self.searchList.sort(self.order.reverse());
How can I get those data back with new order, value and send to WebService call to save the new order to database?
Thanks, Cindy
JS:
JSBin/JSFiddle demonstrating the problem:
self.searchList = Sortable.create(resultList, { store: { /**
localStorage.setItem(sortable.options.group.name, order.join('|')); var tmp = order ? order.toString().split('|') : []; console.log("set:"+tmp); }, }, group: { name: 'shared', pull: 'clone', revertClone: true, sort: true, dataIdAttr: true }, });
HTML:
self.facetsResults = [ { facetID: '0', facet: 'Save %', hitrank: '8371', collapse: 'false', hide: 'false', as: '5', }, { facetID: '1', facet: 'Price', hitrank: '9238', collapse: 'true', hide: 'true', as: '6', }, ];
Before you create an issue, check it:
Bindings: