This page demos how to make a drag and drop table, and make use of REST APIs |
This demo will not work when used by anonymous users, as it uses REST APIs to update the records stored (changing their order). And this is not allowed for anonymous users, as anonymous users don't "own" a record and therefore the update will not happen |
<script> var fixHelperModified = function(e, tr) { var $originals = tr.children(); var $helper = tr.clone(); $helper.children().each(function(index) { AJS.$(this).width($originals.eq(index).width()) }); return $helper; }, updateIndex = function(e, ui) { AJS.$('td.cf_ordernr span', ui.item.parent()).each(function (i) { var currentIndex = AJS.$(this).html(); if (currentIndex != (i+1)) { var entryId = AJS.$(this).closest('tr').attr('confi-data-id'); AJS.$.ajax({ url: 'https://wiki.vertuna.com/ajax/confiforms/rest/update.action?pageId='+ AJS.Meta.get('page-id') +'&f=f&q=id:' + entryId + '&fv=ordernr:' + (i+1), type: "GET", async: true, cache: false, success: function (data) { } }); } AJS.$(this).html(i + 1); }); }; AJS.$(".cf_f_table tbody").sortable({ helper: fixHelperModified, stop: updateIndex }); </script> |
Source code for solution:
|