Skip to main content

I have this inline JS code which I use for drag and drop functionality within table. It works fine when the table is on the main page but now I am trying to execute this within a popup. Any tips?

(function(skuid){var $ = skuid.$;
$(document.body).one(‘pageload’,function(){
var component = skuid.$C(‘sk-3MxwBj-240’),
   listContents = component && component.element.find(‘.nx-list-contents’);
listContents.sortable({
   placeholder: “ui-state-highlight”,
   stop: function( event, ui ) {
       var data = ui.item.data(‘object’),
           model = data.list.model,
           movedRow = data.row,
           target = $(event.target);
       
       target.children().each(function(index,tr){
           var row =  $(tr).data(‘object’).row,
               order = row.Order__c;
          if (index + 1 !== order) {
              model.updateRow(row,‘Order__c’,index+1,{initiatorId:component._GUID});
          }
       });
           
   }
});
});
})(skuid);

Hi Danny. Does the code above reference a unique ID for the table component? “sk-3MxwBj-240” may need to be changed if it should refer to a different component in the popup.


yes that is referencing the new table within the popup.  I believe the issue is that this JS is inline which means it executes after the main pages loads where as I need this to execute after the popup loads.


Okay. In that case, you might need to set up a second (matching) JS inline Snippet for the popup, and trigger that as one of the actions that happens when the popup is opened. Is the popup showing a page include, or is it all part of one page?


I tried that as well. I have a button which when clicked opens the popup.  The action after that renders a snippet.  That did not seem to work either. Let me know if you were referring to a different type of action.


That’s along the lines of what I had imagined. You may also need to remove or replace the line


$(document.body).one('pageload',function(){

since the pageload event doesn’t happen when the button is clicked.


Ok I will try this thanks


That worked thanks!